Key Obtaining Method and Device, and Communications System

ABSTRACT

In a method for security handling in a mobility of a terminal device; a target access and mobility management function (AMF) entity receives a first message for registering a terminal device, sends a second message to a source AMF entity after receiving the first message. The source AMF entity derives a first key based on a key between the source AMF entity and the terminal device, sends the first key to the target AMF entity. The target AMF entity determines to use the first key based on security related information after receiving the first key and determines a communication key between the target AMF entity and the terminal device based on the first key after determining to use the first key.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation of International Patent ApplicationNo. PCT/CN2017/083072, filed on May 4, 2017, which is herebyincorporated by reference in its entirety.

TECHNICAL FIELD

Embodiments of this application relate to communications technologies,and in particular, to a key obtaining method and device, and acommunications system.

BACKGROUND

With the development of communications technologies, communicationsecurity attracts increasing attention. Currently, communicationsecurity is usually ensured through encryption protection and integrityprotection.

In a Long Term Evolution (LTE) system, a termination point of a nonaccess stratum (NAS) is a mobility management entity (MME), and ismainly responsible for mobility management, bearer management, userauthentication, serving gateway (S-GW) selection, packet data networkgateway (P-GW) selection, and the like. In LTE, if an MME accessed by auser equipment (UE) changes because a location of the UE changes(herein, the location of the UE in an idle state changes), a source MMEneeds to send a security context of the UE to a target MME, and then acommunication key between the source MME and the UE is used between thetarget MME and the UE.

In a 5th generation mobile communications (5G) system, an access andmobility management function (AMF) entity is a termination point of aNAS, and is mainly responsible for registration, connection, mobilitymanagement, subscription information authentication, and the like thatare of UE. When an AMF entity accessed by UE changes because a locationof the UE changes (herein, the location of the UE in an idle statechanges), a source AMF entity needs to send a security context of the UEstored in the source AMF entity to a target AMF entity, such that the UEand the target AMF entity can continue communication.

It can be learned that transfer of a security context from one entity toanother entity exists in both LTE and a next generation network, and akey between a target entity and UE is the same as a key between a sourceentity and the UE. This may pose a security risk.

SUMMARY

Embodiments of this application provide a plurality of key obtainingmethods and devices, and a plurality of communications systems, toimprove network security.

According to a first aspect, an embodiment of this application providesa key obtaining method performed by a target AMF entity. The methodincludes receiving, by the target AMF entity, a first message, where thefirst message is used to request to register a terminal device; sending,by the target AMF entity, a second message to a source AMF entity basedon the first message, where the second message includes an identifier ofthe terminal device; receiving, by the target AMF entity, a thirdmessage from the source AMF entity, where the third message is used torespond to the second message, the third message carries a first key,and the first key is obtained by the source AMF entity throughderivation based on a key between the source AMF entity and the terminaldevice; and determining, by the target AMF entity, a communication keybetween the target AMF entity and the terminal device based on securityrelated information and the first key.

In the key obtaining method provided above, the target AMF entitydetermines the communication key between the target AMF entity and theterminal device based on the security related information using anintermediate key sent by the source AMF entity. The intermediate key isobtained by the source AMF entity through derivation based on the keybetween the source AMF entity and the terminal device, and therefore thetarget AMF entity cannot learn of a communication key used between thesource AMF entity and the terminal device. In this way, key isolation isachieved between the target AMF entity and the source AMF entity,thereby effectively avoiding a security risk and improving communicationsecurity.

In a possible design, the method further includes sending, by the targetAMF entity, a NAS security mode command (SMC) to the terminal device,where the NAS SMC carries indication information, and the indicationinformation is used to indicate the terminal device to derive thecommunication key between the terminal device and the target AMF entitybased on the key between the source AMF entity and the terminal device.

Optionally, the security related information includes: a preconfiguredpolicy, where the policy is used to indicate to use a key received fromthe source AMF entity, or the policy is used to indicate to use a keyreceived from an authentication function entity; or key isolationinformation of the target AMF entity, where the key isolationinformation is used to indicate whether a key of the target AMF entityis totally isolated from a key of the source AMF entity; or a securitystatus of the source AMF entity, where the security status is used toindicate whether the source AMF entity is secure.

Further, determining, by the target AMF entity, a communication keybetween the target AMF entity and the terminal device based on securityrelated information and the first key includes determining, by thetarget AMF entity, the communication key between the target AMF entityand the terminal device based on the first key when the security relatedinformation is the preconfigured policy and the policy is used toindicate to use the key received from the source AMF entity, or when thesecurity related information is the key isolation information of thetarget AMF entity and the key isolation information is used to indicatethat the key of the target AMF entity is not totally isolated from thekey of the source AMF entity, or when the security related informationis the security status of the source AMF entity and the security statusis used to indicate that the source AMF entity is secure. Alternatively,determining, by the target AMF entity, a communication key between thetarget AMF entity and the terminal device based on security relatedinformation and the first key includes determining, by the target AMFentity, the communication key between the target AMF entity and theterminal device based on the first key when the target AMF entitydetermines, based on the security related information, to use the keyreceived from the source AMF entity.

Optionally, that the target AMF entity determines, based on the securityrelated information, to use the key received from the source AMF entityincludes determining, by the target AMF entity, to use the key receivedfrom the source AMF entity when the security related information is thepreconfigured policy and the policy is used to indicate to use the keyreceived from the source AMF entity. Alternatively, the target AMFentity determines to use the key received from the source AMF entitywhen the security related information is the key isolation informationof the target AMF entity and the key isolation information is used toindicate that the key of the target AMF entity is not totally isolatedfrom the key of the source AMF entity. Alternatively, the target AMFentity determines to use the key received from the source AMF entitywhen the security related information is the security status of thesource AMF entity and the security status is used to indicate that thesource AMF entity is secure.

Optionally, determining, by the target AMF entity, the communication keybetween the target AMF entity and the terminal device based on the firstkey includes using, by the target AMF entity, the first key as thecommunication key between the target AMF entity and the terminal device.Alternatively, determining, by the target AMF entity, the communicationkey between the target AMF entity and the terminal device based on thefirst key includes deriving, by the target AMF entity, the communicationkey between the target AMF entity and the terminal device based on thefirst key and a random number of the terminal device. Alternatively,determining, by the target AMF entity, the communication key between thetarget AMF entity and the terminal device based on the first keyincludes deriving, by the target AMF entity, the communication keybetween the target AMF entity and the terminal device based on the firstkey and a random number of the target AMF entity. Alternatively,determining, by the target AMF entity, the communication key between thetarget AMF entity and the terminal device based on the first keyincludes deriving, by the target AMF entity, a second key using a keyexchange algorithm based on a random number of the target AMF entity anda random number of the terminal device, and deriving the communicationkey between the target AMF entity and the terminal device based on thefirst key and the second key. Alternatively, determining, by the targetAMF entity, the communication key between the target AMF entity and theterminal device based on the first key includes deriving, by the targetAMF entity, a second key using a key exchange algorithm based on arandom number of the target AMF entity and a random number of theterminal device, deriving a third key based on the first key and therandom number of the target AMF entity, and deriving the communicationkey between the target AMF entity and the terminal device based on thesecond key and the third key.

In a possible design, the first key is obtained by the source AMF entitythrough derivation based on the key between the source AMF entity andthe terminal device and the random number of the terminal device.

In a possible design, the first key is obtained by the source AMF entitythrough derivation based on the key between the source AMF entity andthe terminal device and a random number of the source AMF entity.

In a possible design, the key between the source AMF entity and theterminal device includes a communication key between the source AMFentity and the terminal device or a key shared between the source AMFentity and the terminal device. Additionally, the key shared between thesource AMF entity and the terminal device is a master session key (MSK),or a key generated based on an MSK, or a key generated based on a cipherkey (CK) and an integrity key (IK).

According to a second aspect, an embodiment of this application providesa key obtaining method performed by a target AMF entity. The methodincludes receiving, by the target AMF entity, a first message, where thefirst message is used to request to register a terminal device; sending,by the target AMF entity, a second message to a source AMF entity basedon the first message, where the second message includes an identifier ofthe terminal device; receiving, by the target AMF entity, a thirdmessage from the source AMF entity, where the third message is used torespond to the second message; sending, by the target AMF entity, afourth message to an authentication function entity based on the thirdmessage, where the fourth message is used to request a key, and thefourth message includes the identifier of the terminal device;receiving, by the target AMF entity, a fifth message from theauthentication function entity, where the fifth message carries a firstkey, and the first key is obtained by the authentication function entitythrough derivation based on a key shared between the authenticationfunction entity and the terminal device; and determining, by the targetAMF entity, a communication key between the target AMF entity and theterminal device based on the first key.

In the key obtaining method provided above, the target AMF entitydirectly requests a new key from the authentication function entity todetermine the communication key between the target AMF entity and theterminal device. In this way, key isolation is achieved between thetarget AMF entity and the source AMF entity, thereby effectivelyavoiding a security risk and improving communication security.

In a possible design, the method further includes sending, by the targetAMF entity, a non access stratum security mode command NAS SMC to theterminal device, where the NAS SMC carries indication information, andthe indication information is used to indicate the terminal device toderive the communication key between the terminal device and the targetAMF entity based on the key shared between the authentication functionentity and the terminal device.

In a possible design, sending, by the target AMF entity, a fourthmessage to an authentication function entity includes sending, by thetarget AMF entity, the fourth message to the authentication functionentity based on security related information. Alternatively, the targetAMF entity sends the fourth message to the authentication functionentity when the target AMF entity determines, based on the securityrelated information, not to use a key received from the source AMFentity.

Optionally, the security related information includes: a preconfiguredpolicy, where the policy is used to indicate to use the key receivedfrom the source AMF entity, or the policy is used to indicate to use akey received from the authentication function entity; or key isolationinformation of the target AMF entity, where the key isolationinformation is used to indicate whether a key of the target AMF entityis totally isolated from a key of the source AMF entity; or a securitystatus of the source AMF entity, where the security status is used toindicate whether the source AMF entity is secure.

Further, sending, by the target AMF entity, the fourth message to theauthentication function entity based on security related informationincludes sending, by the target AMF entity, the fourth message to theauthentication function entity when the security related information isthe preconfigured policy and the policy is used to indicate to use thekey received from the authentication function entity. Alternatively, thetarget AMF entity sends the fourth message to the authenticationfunction entity when the security related information is the keyisolation information of the target AMF entity and the key isolationinformation is used to indicate that the key of the target AMF entity istotally isolated from the key of the source AMF entity. Alternatively,the target AMF entity sends the fourth message to the authenticationfunction entity when the security related information is the securitystatus of the source AMF entity and the security status is used toindicate that the source AMF entity is not secure.

Optionally, that the target AMF entity determines, based on the securityrelated information, not to use a key received from the source AMFentity includes determining, by the target AMF entity, not to use thekey received from the source AMF entity when the security relatedinformation is the preconfigured policy and the policy is used toindicate to use the key received from the authentication functionentity. Alternatively, the target AMF entity determines, based on thesecurity related information, not to use the key received from thesource AMF entity when the security related information is the keyisolation information of the target AMF entity and the key isolationinformation is used to indicate that the key of the target AMF entity istotally isolated from the key of the source AMF entity. Alternatively,the target AMF entity determines, based on the security relatedinformation, not to use the key received from the source AMF entity whenthe security related information is the security status of the sourceAMF entity and the security status is used to indicate that the sourceAMF entity is not secure.

In a possible design, determining, by the target AMF entity, acommunication key between the target AMF entity and the terminal devicebased on the first key includes using, by the target AMF entity, thefirst key as the communication key between the target AMF entity and theterminal device. Alternatively, determining, by the target AMF entity, acommunication key between the target AMF entity and the terminal devicebased on the first key includes deriving, by the target AMF entity, thecommunication key between the target AMF entity and the terminal devicebased on the first key and a random number of the target AMF entity; orderiving, by the target AMF entity, a second key using a key exchangealgorithm based on a random number of the target AMF entity and a randomnumber of the terminal device, and deriving the communication keybetween the target AMF entity and the terminal device based on the firstkey and the second key; or deriving, by the target AMF entity, thecommunication key between the target AMF entity and the terminal devicebased on the first key and a random number of the terminal device; orderiving, by the target AMF entity, a second key using a key exchangealgorithm based on a random number of the target AMF entity and a randomnumber of the terminal device, deriving a third key based on the firstkey and the random number of the target AMF entity, and deriving thecommunication key between the target AMF entity and the terminal devicebased on the second key and the third key.

In a possible design, the first key is obtained by the authenticationfunction entity through derivation based on the key shared between theauthentication function entity and the terminal device and the randomnumber of the terminal device.

In a possible design, the first key is obtained by the authenticationfunction entity through derivation based on the key shared between theauthentication function entity and the terminal device and a randomnumber of the authentication function entity.

Optionally, the first message includes the random number of the terminaldevice.

Optionally, the key shared between the authentication function entityand the terminal device is an extended master session key (EMSK), or akey generated based on an EMSK, or a key generated based on a cipher keyCK and an integrity key IK.

According to a third aspect, an embodiment of this application providesa key obtaining method performed by a terminal device. The methodincludes receiving, by the terminal device, a non access stratumsecurity mode command NAS SMC sent by a target AMF entity, where the NASSMC carries indication information, and the indication information isused to indicate the terminal device to derive a communication keybetween the terminal device and the target AMF entity based on a keybetween the terminal device and a source AMF entity, or the indicationinformation is used to indicate the terminal device to derive acommunication key between the terminal device and the target AMF entitybased on a key shared between the terminal device and an authenticationfunction entity; and determining, by the terminal device, thecommunication key between the terminal device and the target AMF entityaccording to the indication information.

In the key obtaining method provided above, the terminal device derivesa corresponding key according to the NAS SMC sent by the target AMFentity, such that the communication key between the terminal device andthe target AMF entity is isolated from a communication key between theterminal device and the source AMF entity, thereby effectively avoidinga security risk and improving communication security.

In a first possible design, determining, by the terminal device, thecommunication key between the terminal device and the target AMF entityaccording to the indication information is such that when the indicationinformation is used to indicate the terminal device to derive thecommunication key between the terminal device and the target AMF entitybased on the key between the terminal device and the source AMF entity,the terminal device derives a first key based on the key between theterminal device and the source AMF entity, and uses the first key as thecommunication key between the terminal device and the target AMF entity.Alternatively, determining, by the terminal device, the communicationkey between the terminal device and the target AMF entity according tothe indication information is such that when the indication informationis used to indicate the terminal device to derive the communication keybetween the terminal device and the target AMF entity based on the keyshared between the terminal device and the authentication functionentity, the terminal device derives a second key based on the key sharedbetween the terminal device and the authentication function entity, anduses the second key as the communication key between the terminal deviceand the target AMF entity.

In a second possible design, the NAS SMC further carries a random numberof the target AMF entity. The determining, by the terminal device, thecommunication key between the terminal device and the target AMF entityaccording to the indication information is such that when the indicationinformation is used to indicate the terminal device to derive thecommunication key between the terminal device and the target AMF entitybased on the key between the terminal device and the source AMF entity,the terminal device derives a first key based on the key between theterminal device and the source AMF entity, and derives the communicationkey between the terminal device and the target AMF entity based on thefirst key and the random number of the target AMF entity. Alternatively,determining, by the terminal device, the communication key between theterminal device and the target AMF entity according to the indicationinformation is such that when the indication information is used toindicate the terminal device to derive the communication key between theterminal device and the target AMF entity based on the key sharedbetween the terminal device and the authentication function entity, theterminal device derives a second key based on the key shared between theterminal device and the authentication function entity, and derives thecommunication key between the terminal device and the target AMF entitybased on the second key and the random number of the target AMF entity.

In a third possible design, the NAS SMC further carries a random numberof the terminal device. The determining, by the terminal device, thecommunication key between the terminal device and the target AMF entityaccording to the indication information is such that when the indicationinformation is used to indicate the terminal device to derive thecommunication key between the terminal device and the target AMF entitybased on the key between the terminal device and the source AMF entity,the terminal device derives a first key based on the key between theterminal device and the source AMF entity, and derives the communicationkey between the terminal device and the target AMF entity based on thefirst key and the random number of the terminal device. Alternatively,determining, by the terminal device, the communication key between theterminal device and the target AMF entity according to the indicationinformation is such that when the indication information is used toindicate the terminal device to derive the communication key between theterminal device and the target AMF entity based on the key sharedbetween the terminal device and the authentication function entity, theterminal device derives a second key based on the key shared between theterminal device and the authentication function entity, and derives thecommunication key between the terminal device and the target AMF entitybased on the second key and the random number of the terminal device.

In a fourth possible design, the NAS SMC further carries a random numberof the terminal device and a random number of the target AMF entity. Thedetermining, by the terminal device, the communication key between theterminal device and the target AMF entity according to the indicationinformation is such that when the indication information is used toindicate the terminal device to derive the communication key between theterminal device and the target AMF entity based on the key between theterminal device and the source AMF entity, the terminal device derives afirst key based on the key between the terminal device and the sourceAMF entity, derives a third key using a key exchange algorithm based onthe random number of the target AMF entity and the random number of theterminal device, and derives the communication key between the terminaldevice and the target AMF entity based on the first key and the thirdkey. Alternatively, determining, by the terminal device, thecommunication key between the terminal device and the target AMF entityaccording to the indication information is such that when the indicationinformation is used to indicate the terminal device to derive thecommunication key between the terminal device and the target AMF entitybased on the key shared between the terminal device and theauthentication function entity, the terminal device derives a second keybased on the key shared between the terminal device and theauthentication function entity, derives a third key using a key exchangealgorithm based on the random number of the target AMF entity and therandom number of the terminal device, and derives the communication keybetween the terminal device and the target AMF entity based on thesecond key and the third key.

In a fifth possible design, the NAS SMC further carries a random numberof the terminal device and a random number of the target AMF entity. Thedetermining, by the terminal device, the communication key between theterminal device and the target AMF entity according to the indicationinformation is such that when the indication information is used toindicate the terminal device to derive the communication key between theterminal device and the target AMF entity based on the key between theterminal device and the source AMF entity, the terminal device derives afirst key based on the key between the terminal device and the sourceAMF entity, derives a fourth key based on the first key and the randomnumber of the target AMF entity, derives a third key using a keyexchange algorithm based on the random number of the target AMF entityand the random number of the terminal device, and derives thecommunication key between the terminal device and the target AMF entitybased on the third key and the fourth key. Alternatively, determining,by the terminal device, the communication key between the terminaldevice and the target AMF entity according to the indication informationis such that when the indication information is used to indicate theterminal device to derive the communication key between the terminaldevice and the target AMF entity based on the key shared between theterminal device and the authentication function entity, the terminaldevice derives a second key based on the key shared between the terminaldevice and the authentication function entity, derives a fifth key basedon the second key and the random number of the target AMF entity,derives a third key using a key exchange algorithm based on the randomnumber of the target AMF entity and the random number of the terminaldevice, and derives the communication key between the terminal deviceand the target AMF entity based on the third key and the fifth key.

Optionally, deriving, by the terminal device, a first key based on thekey between the terminal device and the source AMF entity includesderiving, by the terminal device, the first key based on the key betweenthe terminal device and the source AMF entity and the random number ofthe terminal device. Alternatively, deriving, by the terminal device, afirst key based on the key between the terminal device and the sourceAMF entity includes deriving, by the terminal device, the first keybased on the key between the terminal device and the source AMF entityand a random number of the source AMF entity.

Optionally, deriving, by the terminal device, a second key based on thekey shared between the terminal device and the authentication functionentity includes deriving, by the terminal device, the second key basedon the key shared between the terminal device and the authenticationfunction entity and the random number of the terminal device.Alternatively, deriving, by the terminal device, a second key based onthe key shared between the terminal device and the authenticationfunction entity includes deriving, by the terminal device, the secondkey based on the key shared between the terminal device and theauthentication function entity and a random number of the authenticationfunction entity.

Optionally, the NAS SMC further carries the random number of theauthentication function entity.

In a possible design, before receiving, by the terminal device, a NASSMC sent by a target AMF entity, the method further includes sending, bythe terminal device, a first message to an access network (AN) node,where the first message is used to request to register the terminaldevice; or sending, by the terminal device, a first message to thetarget AMF entity, where the first message is used to request toregister the terminal device.

Optionally, the first message carries the random number of the terminaldevice.

In a possible design, the key shared between the authentication functionentity and the terminal device is an extended master session key (EMSK),or a key generated based on an EMSK, or a key generated based on acipher key (CK) and an integrity key (IK). The key between the sourceAMF entity and the terminal device includes a communication key betweenthe source AMF entity and the terminal device or a key shared betweenthe source AMF entity and the terminal device, and the key sharedbetween the source AMF entity and the terminal device is a mastersession key (MSK), or a key generated based on an MSK, or a keygenerated based on a cipher key (CK) and an integrity key (IK).

According to a fourth aspect, an embodiment of this application providesa key obtaining method performed by an authentication function entity.The method includes receiving, by the authentication function entity, afirst message sent by an AMF entity, where the first message is used torequest a key, and the first message includes an identifier of aterminal device; deriving, by the authentication function entity, afirst key based on a key shared between the authentication functionentity and the terminal device; and sending, by the authenticationfunction entity, a second message to the AMF entity, where the secondmessage carries the first key.

In the key obtaining method provided above, the authentication functionentity provides a new key for the AMF entity, such that the AMF entitydetermines a communication key between the AMF entity and the terminaldevice based on the new key provided by the authentication functionentity. In this way, key isolation is achieved between different AMFentities, thereby avoiding a security risk and improving communicationsecurity.

In a possible design, deriving, by the authentication function entity, afirst key based on a key shared between the authentication functionentity and the terminal device includes deriving, by the authenticationfunction entity, the first key based on the key shared between theauthentication function entity and the terminal device and a randomnumber of the terminal device.

Optionally, the first message further includes the random number of theterminal device.

In a possible design, deriving, by the authentication function entity, afirst key based on a key shared between the authentication functionentity and the terminal device includes deriving, by the authenticationfunction entity, the first key based on the key shared between theauthentication function entity and the terminal device and a randomnumber of the authentication function entity.

Optionally, the key shared between the authentication function entityand the terminal device is an extended master session key (EMSK), or akey generated based on an EMSK, or a key generated based on a cipher key(CK) and an integrity key (IK).

According to a fifth aspect, to implement the foregoing key obtainingmethod provided in the first aspect, an embodiment of this applicationprovides a key obtaining apparatus, and the apparatus has a function ofimplementing the foregoing key obtaining method. The function may beimplemented by hardware, or may be implemented by hardware executingcorresponding software. The hardware or software includes one or moremodules corresponding to the foregoing function.

In a possible implementation of the fifth aspect, the apparatus includesa plurality of function modules or units, configured to implement anykey obtaining method in the first aspect.

According to a sixth aspect, an embodiment of this application providesan AMF entity, and a structure of the AMF entity may include a processorand a transceiver. The processor is configured to support the AMF entityin performing corresponding functions in any key obtaining method in thefirst aspect. The transceiver is configured to support communicationbetween the AMF entity and another network device, and may be, forexample, a corresponding radio frequency module or baseband module. TheAMF entity may further include a memory. The memory is configured to becoupled to the processor, and stores a program instruction and data thatmay be used by the AMF entity to perform the foregoing key obtainingmethod.

According to a seventh aspect, an embodiment of this applicationprovides a computer storage medium, configured to store a computersoftware instruction used by the foregoing target AMF entity. Thecomputer storage medium includes a program designed to perform the firstaspect.

According to an eighth aspect, an embodiment of this applicationprovides a computer program product, including an instruction. When thecomputer program product is executed by a computer, the instructionenables the computer to perform functions performed by the target AMFentity in the foregoing method.

According to a ninth aspect, to implement the foregoing key obtainingmethod provided in the second aspect, an embodiment of this applicationprovides a key obtaining apparatus, and the apparatus has a function ofimplementing the foregoing key obtaining method. The function may beimplemented by hardware, or may be implemented by hardware executingcorresponding software. The hardware or software includes one or moremodules corresponding to the foregoing function.

In a possible implementation of the ninth aspect, the apparatus includesa plurality of function modules or units, configured to implement anykey obtaining method in the second aspect.

According to a tenth aspect, an embodiment of this application providesan AMF entity, and a structure of the AMF entity may include a processorand a transceiver. The processor is configured to support the AMF entityin performing corresponding functions in any key obtaining method in thesecond aspect. The transceiver is configured to support communicationbetween the AMF entity and another network device, and may be, forexample, a corresponding radio frequency module or baseband module. TheAMF entity may further include a memory. The memory is configured to becoupled to the processor, and stores a program instruction and data thatmay be used by the AMF entity to perform the foregoing key obtainingmethod.

According to an eleventh aspect, an embodiment of this applicationprovides a computer storage medium, configured to store a computersoftware instruction used by the foregoing target AMF entity. Thecomputer storage medium includes a program designed to perform thesecond aspect.

According to a twelfth aspect, an embodiment of this applicationprovides a computer program product, including an instruction. When thecomputer program is executed by a computer, the instruction enables thecomputer to perform functions performed by the target AMF entity in theforegoing method.

According to a thirteenth aspect, to implement the foregoing keyobtaining method provided in the third aspect, an embodiment of thisapplication provides a key obtaining apparatus, and the apparatus has afunction of implementing the foregoing key obtaining method. Thefunction may be implemented by hardware, or may be implemented byhardware executing corresponding software. The hardware or softwareincludes one or more modules corresponding to the foregoing function.

In a possible implementation of the thirteenth aspect, the apparatusincludes a plurality of function modules or units, configured toimplement any key obtaining method in the third aspect.

According to a fourteenth aspect, an embodiment of this applicationprovides a terminal device, and a structure of the terminal device mayinclude a processor and a transceiver. The processor is configured tosupport the terminal device in performing corresponding functions in anykey obtaining method in the third aspect. The transceiver is configuredto support communication between the terminal device and another networkdevice, and may be, for example, a corresponding radio frequency moduleor baseband module. The terminal device may further include a memory.The memory is configured to be coupled to the processor, and stores aprogram instruction and data that may be used by the terminal device toperform the foregoing key obtaining method.

According to a fifteenth aspect, an embodiment of this applicationprovides a computer storage medium, configured to store a computersoftware instruction used by the foregoing terminal device. The computerstorage medium includes a program designed to perform the third aspect.

According to a sixteenth aspect, an embodiment of this applicationprovides a computer program product, including an instruction. When thecomputer program is executed by a computer, the instruction enables thecomputer to perform functions performed by the terminal device in theforegoing method.

According to a seventeenth aspect, to implement the foregoing keyobtaining method provided in the fourth aspect, an embodiment of thisapplication provides a key obtaining apparatus, and the apparatus has afunction of implementing the foregoing key obtaining method. Thefunction may be implemented by hardware, or may be implemented byhardware executing corresponding software. The hardware or softwareincludes one or more modules corresponding to the foregoing function.

In a possible implementation of the seventeenth aspect, the apparatusincludes a plurality of function modules or units, configured toimplement any key obtaining method in the third aspect.

According to an eighteenth aspect, an embodiment of this applicationprovides an authentication function entity, and a structure of theauthentication function entity may include a processor and atransceiver. The processor is configured to support the authenticationfunction entity in performing corresponding functions in any keyobtaining method in the fourth aspect. The transceiver is configured tosupport communication between the authentication function entity andanother network device, and may be, for example, a corresponding radiofrequency module or baseband module. The authentication function entitymay further include a memory. The memory is configured to be coupled tothe processor, and stores a program instruction and data that may beused by the authentication function entity to perform the foregoing keyobtaining method.

According to a nineteenth aspect, an embodiment of this applicationprovides a computer storage medium, configured to store a computersoftware instruction used by the authentication function entity. Thecomputer storage medium includes a program designed to perform thefourth aspect.

According to a twentieth aspect, an embodiment of this applicationprovides a computer program product, including an instruction. When thecomputer program is executed by a computer, the instruction enables thecomputer to perform functions performed by the authentication functionentity in the foregoing method.

According to a twenty-first aspect, an embodiment of this applicationprovides a communications system, including a terminal device having thekey obtaining apparatus provided in the thirteenth aspect, a target AMFentity having the key obtaining apparatus provided in the fifth aspector the ninth aspect, an authentication function entity having the keyobtaining apparatus provided in the seventeenth aspect, and a source AMFentity.

According to a twenty-second aspect, an embodiment of this applicationprovides a communications system, including the terminal device providedin the fourteenth aspect, the target AMF entity provided in the sixthaspect or the tenth aspect, the authentication function entity providedin the eighteenth aspect, and a source AMF entity.

Compared with conventional techniques, in the methods, devices, andsystems provided in the embodiments of this application, the target AMFentity determines, using the intermediate key sent by the source AMFentity, the communication key used between the target AMF entity and theterminal device, or the target AMF entity requests a new key from theauthentication function entity to determine the communication key usedbetween the target AMF entity and the terminal device, and instructs theterminal device to derive a corresponding key. In this way, keyisolation is achieved between the target AMF entity and the source AMFentity, thereby effectively avoiding a security risk and improvingnetwork security.

BRIEF DESCRIPTION OF DRAWINGS

FIG. 1 is a schematic architectural diagram of an application scenarioaccording to an embodiment of this application;

FIG. 2A and FIG. 2B are schematic flowcharts of a key obtaining methodaccording to an embodiment of this application;

FIG. 3 is a schematic flowchart of a key obtaining method according toan embodiment of this application;

FIG. 4A and FIG. 4B are schematic flowcharts of a key obtaining methodaccording to an embodiment of this application;

FIG. 5 is a schematic flowchart of a key obtaining method according toan embodiment of this application;

FIG. 6 is a schematic structural diagram of a key obtaining apparatusaccording to an embodiment of this application;

FIG. 7 is a schematic structural diagram of a key obtaining apparatusaccording to an embodiment of this application;

FIG. 8 is a schematic structural diagram of a key obtaining apparatusaccording to an embodiment of this application;

FIG. 9 is a schematic structural diagram of a key obtaining apparatusaccording to an embodiment of this application;

FIG. 10 is a schematic structural diagram of a key obtaining apparatusaccording to an embodiment of this application;

FIG. 11 is a schematic structural diagram of an AMF entity according toan embodiment of this application;

FIG. 12 is a schematic structural diagram of an AMF entity according toan embodiment of this application;

FIG. 13 is a schematic structural diagram of a terminal device accordingto an embodiment of this application;

FIG. 14 is a schematic structural diagram of an authentication functionentity according to an embodiment of this application; and

FIG. 15 is a schematic structural diagram of an AMF entity according toan embodiment of this application.

DESCRIPTION OF EMBODIMENTS

The technical solutions provided in the embodiments of this applicationare applicable to a mobile network. The mobile network in theembodiments of this application is a combination of different mobilenetwork element types, transmission networks, and network managementsubsystems. The different mobile network element types undertakedifferent network functions, such as a base station, a controller, and acore network (CN). The transmission network is used to connect to amobile network element, and the network management subsystem is used tomanage a mobile network element and a transmission network.

A terminal device in the embodiments of this application may be asmartphone, a tablet computer, a pad, UE, or the like, or may be anInternet of Things terminal device such as a smart water meter. Themobile network and the terminal device are interconnected using awireless interface, and a plurality of wireless technologies can be usedby the wireless interface. In the embodiments of this application, thewireless technology that can be used by the wireless interface includesa 4th generation mobile communications technology (4G), or may be 5Gthat is currently being studied or even another mobile communicationstechnology that is to be subsequently studied.

In the embodiments of this application, a 3rd Generation PartnershipProject (3GPP) system shown in FIG. 1 is used as an example to describean application scenario of this application. FIG. 1 is a schematicarchitectural diagram of an application scenario according to anembodiment of this application. As shown in FIG. 1, logical functionunits in the system architecture mainly include the following.

(1) (Radio) access network ((R)AN): The (R)AN provides network resourcesfor access of a terminal device.

(2) AMF entity: The AMF entity is mainly responsible for a terminationpoint of a radio access network control plane, a termination point ofnon access signaling, mobility management, lawful interception, accessauthorization/authentication, and the like.

(3) Session management function (SMF) entity: The SMF entity is mainlyresponsible for session management, Internet Protocol (IP) addressassignment and management of a terminal device, manageable user planefunction selection, a termination point of a policy control and chargingfunction interface, downlink data notification, and the like.

(4) User plane function (UPF) entity: The UPF entity is mainlyresponsible for session and bearer management, Internet Protocol (IP)address assignment, and the like.

(5) Authentication server function (AUSF) entity: The AUSF entity ismainly responsible for user authentication, and the like. Authenticationcredential repository and processing function (ARPF) entity: The ARPFentity is mainly responsible for storing a long-term security truststatus of a terminal device.

(6) Data Network (DN): The DN is a network for transmitting data, suchas an Internet network.

(7) Policy control functionality: The function entity includes a policycontrol decision function, and is mainly responsible for providing apolicy for a network.

It should be noted that, because a 5G structure is not determined, thearchitecture in the embodiments of this application is merely used as anexample to describe the solutions provided in this application. Forexample, the system architecture may further include a security anchorfunction (SEAF) entity (mainly responsible for a function related to anetwork security anchor), and the SEAF entity may be an independentnetwork element in the system architecture, or may be a network elementthat is integrated with an existing function entity. For example, theSEAF entity is integrated with an access and mobility management entity,or may be integrated with another network element. Therefore, thearchitecture in the foregoing application scenario is not intended tolimit this application.

In the following embodiments of this application, a network elementdefined at a higher level is used, and is referred to as anauthentication function entity to represent an entity that is used toauthenticate a server function, for example, an AUSF, an ARPF, or aSEAF. The authentication function entity may be a network elementdeployed in a core network, or may be an application server outside acore network, or may be a function of an existing network element (forexample, a function module inside an AUSF entity or an AMF entity), ormay be another separated network element in the future.

A key obtaining method provided in the embodiments of this applicationmay be applied to a 5G communications scenario, or may be applied to a4G communications scenario. When the key obtaining method is used in the4G scenario, a corresponding network element relationship is: an AMF andan SMF in 5G are replaced with an MME in 4G, a UPF in 5G is replacedwith an S-GW and a P-GW in 4G, and an AUSF and an ARPF in 5G arereplaced with a home subscriber server (HSS) in 4G.

The following describes in detail the technical solutions usingembodiments of the application. The technical solutions of thisapplication are mainly applied to a handover scenario in which alocation of a terminal device in an idle state changes. In thisscenario, a security context of the terminal device may be transferredfrom one entity to another entity, and a key between a target entity andthe terminal device is the same as a key between a source entity and theterminal device. This may pose a security risk. For example, once a keyis leaked, an operator cannot learn whether the key is leaked from thesource entity or the target entity, and therefore responsibilitiescannot be effectively divided; or if one of the source entity and thetarget entity is attacked, the other is also affected. Therefore, whenthe security context of the terminal device is transferred from oneentity to another entity, how to perform key isolation becomes an urgentproblem to be resolved.

In view of the above, the embodiments of this application provide aplurality of key obtaining methods and devices, and a plurality ofcommunications systems, to improve network security. The followingembodiments may be mutually combined, and same or similar concepts orprocesses may not be repeatedly described in some embodiments.

FIG. 2A and FIG. 2B are schematic flowcharts of a key obtaining methodaccording to an embodiment of this application. Details are as follows.

S201. A target AMF entity receives a first message.

The first message may be used to request to register a terminal device,and the first message may be a registration request message.

In an example, when a location of the terminal device in an idle statechanges, the terminal device sends a registration request to a (R)AN,and the (R)AN selects a target AMF entity for the terminal deviceaccording to the registration request of the terminal device, and sendsthe registration request of the terminal device to the target AMFentity.

In another example, a (R)AN detects that a location of the terminaldevice changes, selects a target AMF entity for the terminal devicebased on a current location of the terminal device, and sends aregistration request to the target AMF entity.

In still another example, a (R)AN detects that a location of theterminal device changes, selects a target AMF entity for the terminaldevice based on a current location of the terminal device, and notifiesthe terminal device of the selected target AMF entity, and the terminaldevice sends a registration request to the target AMF entity.

In the accompanying drawing (FIG. 2A and FIG. 2B) corresponding to thisembodiment, an example in which the (R)AN sends the first message to thetarget AMF entity is used for description.

S202. The target AMF entity sends a second message to a source AMFentity based on the first message.

The second message may be used to request a security context of theterminal device, and may be, for example, an information requestmessage.

In addition, the second message may include an identifier of theterminal device, for example, a user permanent identity or a temporaryidentity such as an international mobile subscriber identity (IMSI) or aglobally unique temporary UE identity (GUTI), such that the source AMFentity sends the security context corresponding to the identifier of theterminal device to the target AMF entity.

S203. The target AMF entity receives a third message from the source AMFentity, where the third message carries a first key.

The third message may be used to respond to the second message, and thethird message may be used to send the security context of the terminaldevice to the target AMF entity. For example, the third message is aninformation response message.

The first key (referred to as K_(oAMF)′ below) carried in the thirdmessage may be obtained by the source AMF entity through derivationbased on a key (referred to as a second key below and marked asK_(oAMF)) between the source AMF entity and the terminal device.

Further, the first key may be obtained by the source AMF entity throughderivation based on the key between the source AMF entity and theterminal device and a random number of the terminal device, or may beobtained by the source AMF entity through derivation based on the keybetween the source AMF entity and the terminal device and a randomnumber of the source AMF entity.

The key between the source AMF entity and the terminal device includes acommunication key between the source AMF entity and the terminal deviceor a key shared between the source AMF entity and the terminal device.In some embodiments, the key shared between the source AMF entity andthe terminal device may be an MSK, or a key generated based on an MSK,or a key generated based on a CK and an IK. The IK and the CK may bederived by an AUSF or an ARPF based on a permanent key K.

It should be noted that the communication key between the source AMFentity and the terminal device is a key used for communication betweenthe source AMF entity and the terminal device. For example, the terminaldevice uses the communication key to perform encryption protectionprocessing or integrity protection processing on data or signaling thatis to be sent by the terminal device to the source AMF entity, and thensends processed data or signaling to the source AMF entity. Meanings ofcommunication keys in this specification are similar, and details arenot described.

In an example, the source AMF entity may derive K_(oAMF)′ using a keyderivation function (KDF) based on K_(oAMF). In this way, backwardsecurity of a key can be implemented, to be specific, the target AMFentity cannot derive a key used by the source AMF entity. For example,if the source AMF entity cannot determine whether the target AMF entityis secure, the source AMF may use this manner instead of directlysending a key used between the source AMF entity and the terminal deviceto the target AMF entity.

In another example, the first key may be obtained by the source AMFentity through derivation based on the key between the source AMF entityand the terminal device and the random number of the terminal device. Inother words, the source AMF entity may derive K_(oAMF)′ using a KDFbased on K_(oAMF) and the random number of the terminal device.

The random number of the terminal device is carried in the registrationrequest message sent by the terminal device to the (R)AN, and then the(R)AN sends, to the target AMF entity, the first message that carriesthe random number of the terminal device; or the random number of theterminal device is carried when the terminal device sends theregistration request message of the terminal device to the target AMFentity. Then the target AMF entity sends, to the source AMF entity, thesecond message that carries the random number of the terminal device,and the source AMF entity uses the random number of the terminal deviceas an input parameter when deriving the first key (K_(oAMF)′).

In still another example, the first key is obtained by the source AMFentity through derivation based on the key between the source AMF entityand the terminal device and the random number of the source AMF entity.In some embodiments, the source AMF entity may derive the first key(K_(oAMF)′) using a KDF based on K_(oAMF) and the random number of thesource AMF entity. Because a capability of generating a random number bythe terminal device may be poorer than that of a network side, that is,randomness is not sufficiently strong, the source AMF entity uses therandom number of the source AMF entity as an input parameter whenderiving the first key (K_(oAMF)′), to enhance a key isolation effect.

In this case, the third message that is sent by the source AMF entityand that is received by the target AMF entity in S203 may further carrythe random number of the source AMF entity.

S204. The target AMF entity determines, based on security relatedinformation, whether to use the first key.

If the first key is to be used, S205 to S207 are performed; if the firstkey is not to be used, S208 to S212 are performed.

The security related information may include at least one of apreconfigured policy, key isolation information of the target AMFentity, or a security status of the source AMF entity.

The preconfigured policy is used to indicate to use a key received fromthe source AMF entity, or the policy is used to indicate to use a keyreceived from an authentication function entity.

The key isolation information is used to indicate whether a key of thetarget AMF entity is totally isolated from a key of the source AMFentity. For example, when the target AMF entity can derive the keybetween the source AMF entity and the terminal device using a keyprovided by the source AMF entity, the key of the target AMF entity isnot totally isolated from the key of the source AMF entity. When thetarget AMF entity cannot derive the key between the source AMF entityand the terminal device based on a key provided by the source AMFentity, and the source AMF entity cannot derive a communication keybetween the target AMF entity and the terminal device either, the key ofthe target AMF entity is totally isolated from the key of the source AMFentity.

The security status of the source AMF entity is used to indicate whetherthe source AMF entity is secure. Whether the source AMF entity is securemay be whether a location of the source AMF entity is secure, whetherthe source AMF entity and the target AMF entity are in a same networkdomain, whether the source AMF entity is trusted, or the like. Forexample, if the location of the source AMF entity is secure, the sourceAMF entity is secure, and if the location of the source AMF entity isnot secure, the source AMF entity is not secure; or if the source AMFentity and the target AMF entity are in a same network domain, thesource AMF entity is secure, and if the source AMF entity and the targetAMF entity are not in a same network domain, the source AMF entity isnot secure; or if the source AMF entity is trusted, the source AMFentity is secure, and if the source AMF entity is not trusted, thesource AMF entity is not secure.

For example, step S204 may be implemented in one or more of thefollowing manners.

When the security related information is the preconfigured policy andthe policy is used to indicate to use the key received from the sourceAMF entity, the target AMF entity determines to use the key receivedfrom the source AMF entity.

When the security related information is the key isolation informationof the target AMF entity and the key isolation information of the targetAMF entity is used to indicate that the key of the target AMF entity isnot totally isolated from the key of the source AMF entity, the targetAMF entity determines to use the key received from the source AMFentity.

When the security related information is the security status of thesource AMF entity and the security status is used to indicate that thesource AMF entity is secure, the target AMF entity determines to use thekey received from the source AMF entity.

For example, step S204 may alternatively be implemented in one or moreof the following manners.

When the security related information is the preconfigured policy andthe policy is used to indicate to use the key received from theauthentication function entity, the target AMF entity determines not touse the key received from the source AMF entity.

When the security related information is the key isolation informationof the target AMF entity and the key isolation information of the targetAMF entity is used to indicate that the key of the target AMF entity istotally isolated from the key of the source AMF entity, the target AMFentity determines not to use the key received from the source AMFentity.

When the security related information is the security status of thesource AMF entity and the security status is used to indicate that thesource AMF entity is not secure, the target AMF entity determines not touse the key received from the source AMF entity.

Obviously, content included in the security related information may beused together. For example, when the security related informationincludes the preconfigured policy and the security status of the sourceAMF entity, whether to use the first key is determined based on thesecurity status of the source AMF entity. For another example, when thesecurity related information includes the key isolation information ofthe target AMF entity and the security status of the source AMF entity,if the key isolation information of the target AMF entity indicates thatthe key of the target AMF entity is totally isolated from the key of thesource AMF entity, and the security status of the source AMF entityindicates that the source AMF entity is secure, it is determined not touse the first key. Details are not described.

S205. The target AMF entity determines a communication key between thetarget AMF entity and a terminal device based on the first key.

S206. The target AMF entity sends a NAS SMC to the terminal device,where the NAS SMC carries indication information.

The indication information is used to indicate the terminal device toderive the communication key between the terminal device and the targetAMF entity based on the key between the source AMF entity and theterminal device, for example, instruct the terminal device to derive thecommunication key between the terminal device and the target AMF entitybased on the second key (K_(oAMF)).

In an example, because the key between the source AMF entity and theterminal device includes the communication key between the source AMFentity and the terminal device or the key shared between the source AMFentity and the terminal device, when the first key (K_(oAMF)′) isderived based on the communication key between the source AMF entity andthe terminal device, the indication information may be used to indicatethe terminal device to derive the first key (K_(oAMF)′) based on thecommunication key between the source AMF entity and the terminal device,or used to indicate to derive the communication key between the sourceAMF entity and the terminal device based on the key shared between thesource AMF entity and the terminal device and then derive the first key(K_(oAMF)′) based on the communication key between the source AMF entityand the terminal device; or when the first key (K_(oAMF)′) is derivedbased on the key shared between the source AMF entity and the terminaldevice, the indication information is used to indicate the terminaldevice to derive the first key (K_(oAMF)′) based on the key sharedbetween the source AMF entity and the terminal device.

S207. The terminal device determines the communication key between theterminal device and the target AMF entity according to the indicationinformation.

S208. The target AMF entity sends a fourth message to an authenticationfunction entity.

The fourth message may be used for a key request, and may be, forexample, a key request message, and the fourth message may carry theidentifier of the terminal device, such that the authentication functionentity obtains, based on the identifier of the terminal device, a keyshared between the authentication function entity and the terminaldevice (which may be referred to as a fourth key and marked as K_(AUF)).

The key shared between the authentication function entity and theterminal device is an EMSK, or a key generated based on an EMSK, or akey generated based on a CK and an IK.

For example, after performing subscription authentication on theterminal device, the authentication function entity may generate twokeys (it is assumed that the two keys are a key A and a key B), and thekey A is retained in the authentication function entity. In this case,the key A may be used as K_(AUF), and the key B is sent to anothernetwork element (for example, an AMF/MME).

In a possible case, the Extensible Authentication Protocol (EAP) is usedin an authentication process. Because two keys: an EMSK and an MSK aregenerated after EAP authentication is completed, the EMSK may beconsidered as the key A, the MSK is considered as the key B, and theEMSK is shared (not sent) between the authentication function entity andthe terminal device, and the MSK is sent to another network element suchas the source AMF. In this case, K_(AUF) may be the EMSK, and then theMSK may be considered as K_(oAMF). If the target AMF entity does not usean intermediate key derived using K_(oAMF), the target AMF entityrequests a key from the authentication function entity. In other words,a new key is derived using K_(AUF) shared between the terminal deviceand the authentication function entity, and the source AMF does not knowthe derived new key.

In another possible case, if the Evolved Packet System (EPS) protocol isused in an authentication process, K_(AUF) may be a key generated usinga CK and an IK. Both the CK and the IK are generated using a permanentkey K. For example, in LTE, the CK and the IK may be generated using thepermanent key K, and then K_(ASME) is generated using the CK and the IK.In this embodiment, two keys K_(ASME) may be generated using the CK andthe IK. One similar to K_(ASME) in 4G is delivered to an MME, and theother is stored in the authentication function entity as K_(AUF).

For example, the third message may carry an address of theauthentication function entity, and the target AMF entity may send thefourth message to the authentication function entity based on theaddress of the authentication function entity, or the target AMF entitymay select the authentication function entity based on the identifier ofthe terminal device, and then send the fourth message to theauthentication function entity.

S209. The target AMF entity receives a fifth message sent by theauthentication function entity, where the fifth message carries a thirdkey.

The fifth message may be used to respond to the fourth message, and maybe, for example, a key response message.

The third key (referred to as K_(AUF)′ below) may be obtained by theauthentication function entity through derivation based on the key(K_(AUF)) shared between the authentication function entity and theterminal device.

In a first optional implementation, the authentication function entitymay derive the third key (K_(AUF)′) using a KDF based on the fourth key(K_(AUF)).

In a second optional implementation, the third key is obtained by theauthentication function entity through derivation based on the keyshared between the authentication function entity and the terminaldevice and the random number of the terminal device. For example, theauthentication function entity may derive the third key (K_(AUF)′) usingthe KDF based on the fourth key (K_(AUF)) and the random number of theterminal device.

The random number of the terminal device may be carried when theterminal device sends the registration request message to the (R)AN, andthen the (R)AN sends, to the target AMF entity, the first message thatcarries the random number of the terminal device; or the random numberof the terminal device may be carried when the terminal device sends theregistration request message of the terminal device to the target AMFentity. Then the target AMF entity sends, to the authentication functionentity, the fourth message that carries the random number of theterminal device, and the authentication function entity uses the randomnumber of the terminal device as an input parameter when deriving thethird key (K_(AUF)′).

In a third optional implementation, the third key is obtained by theauthentication function entity through derivation based on the keyshared between the authentication function entity and the terminaldevice and a random number of the authentication function entity. Insome aspects, the authentication function entity may derive the thirdkey (K_(AUF)′) using a KDF based on the fourth key (K_(AUF)) and therandom number of the authentication function entity. Because acapability of generating a random number by the terminal device may bepoorer than that of a network side, that is, randomness is notsufficiently strong, the authentication function entity uses the randomnumber of the authentication function entity as an input parameter whenderiving the third key (K_(AUF)′).

S210. The target AMF entity determines a communication key between thetarget AMF entity and a terminal device based on the third key.

S211. The target AMF entity sends a NAS SMC to the terminal device.

The NAS SMC carries indication information, and the indicationinformation is used to indicate the terminal device to derive thecommunication key between the terminal device and the target AMF entitybased on the key (K_(AUF)) shared between the authentication functionentity and the terminal device.

Optionally, the NAS SMC further includes a key set identifier, and thekey set identifier is similar to KSI_ASME in LTE, and is used toindicate a root key to be used by the terminal device for derivation.The key set identifier may have a same format as KSI_AMSE.

S212. The terminal device determines the communication key between theterminal device and the target AMF entity according to indicationinformation.

Optionally, the method may further include the following steps.

S213. The terminal device sends a NAS security mode complete (SMP)message to the target AMF entity.

S214. The target AMF entity sends a sixth message to the terminaldevice.

The sixth message may be used to notify the terminal device thatregistration of the terminal device is accepted, and may be, forexample, a registration accept message.

In the key obtaining method provided in this embodiment, the target AMFentity dynamically determines whether to use an intermediate key sent bythe source AMF entity to determine the communication key used betweenthe target AMF entity and the terminal device, or request a new key fromthe authentication function entity to determine the communication keyused between the target AMF entity and the terminal device, andinstructs the terminal device to derive a corresponding key. In thisway, key isolation is achieved between the target AMF entity and thesource AMF entity, thereby effectively avoiding a security risk andimproving network security.

Optionally, in a first implementation scenario of the foregoingembodiment, S205 to S207 may be implemented in the following manners.

Manner 1: In an implementation process of S205, the target AMF entityuses the first key (K_(oAMF)′) as the communication key between thetarget AMF entity and the terminal device.

Case 1: The first key (K_(oAMF)′) is derived by the source AMF entitybased on the key (K_(oAMF)) between the terminal device and the sourceAMF entity.

Correspondingly, in S207, the terminal device derives the first key(K_(oAMF)′) based on the key (K_(oAMF)) between the terminal device andthe source AMF entity, and uses the first key (K_(oAMF)′) as thecommunication key between the terminal device and the target AMF entity.

Case 2: The first key (K_(oAMF)′) is derived by the source AMF entitybased on the key (K_(oAMF)) between the terminal device and the sourceAMF entity and the random number of the terminal device.

Correspondingly, in S207, the terminal device derives the first key(K_(oAMF)′) based on the key (K_(oAMF)) between the terminal device andthe source AMF entity and the random number of the terminal device, anduses the first key (K_(oAMF)′) as the communication key between theterminal device and the target AMF entity.

In this case, in S206, the NAS SMC sent by the target AMF entity to theterminal device may further carry the random number of the terminaldevice.

It may be understood that, in this case, the random number of theterminal device may be further used by the terminal device to detectreplay, to prevent a replay attack.

Case 3: The first key (K_(oAMF)′) is derived by the source AMF entitybased on the key (K_(oAMF)) between the terminal device and the sourceAMF entity and the random number of the source AMF entity.

Correspondingly, in S207, the terminal device derives the first key(K_(oAMF)′) based on the key (K_(oAMF)) between the terminal device andthe source AMF entity and the random number of the source AMF entity,and uses the first key (K_(oAMF)′) as the communication key between theterminal device and the target AMF entity.

In this case, in S206, the NAS SMC sent by the target AMF entity to theterminal device may further carry the random number of the source AMFentity.

It should be noted that, in case 3, in S206, the NAS SMC sent by thetarget AMF entity to the terminal device may further carry the randomnumber of the terminal device. In this case, the random number of theterminal device is used only by the terminal device to detect replay, toprevent a replay attack.

Manner 2: In an implementation process of S205, the target AMF entityderives the communication key between the target AMF entity and theterminal device based on the first key (K_(oAMF)′) and the random numberof the terminal device. Further, in S206, the NAS SMC sent by the targetAMF entity to the terminal device further carries the random number ofthe terminal device.

Case 1: The first key (K_(oAMF)′) is derived by the source AMF entitybased on the key (K_(oAMF)) between the terminal device and the sourceAMF entity.

Correspondingly, in S207, the terminal device derives the first key(K_(oAMF)′) based on the key (K_(oAMF)) between the terminal device andthe source AMF entity, and derives the communication key between theterminal device and the target AMF entity based on the first key(K_(oAMF)′) and the random number of the terminal device.

Case 2: The first key (K_(oAMF)′) is derived by the source AMF entitybased on the key (K_(oAMF)) between the terminal device and the sourceAMF entity and the random number of the terminal device.

Correspondingly, in S207, the terminal device derives the first key(K_(oAMF)′) based on the key (K_(oAMF)) between the terminal device andthe source AMF entity and the random number of the terminal device, andderives the communication key between the terminal device and the targetAMF entity based on the first key (K_(oAMF)′) and the random number ofthe terminal device. It may be understood that, in this case, the randomnumber of the terminal device may be further used by the terminal deviceto detect replay, to prevent a replay attack.

Case 3: The first key (K_(oAMF)′) is derived by the source AMF entitybased on the key (K_(oAMF)) between the terminal device and the sourceAMF entity and the random number of the source AMF entity.

Correspondingly, in S207, the terminal device derives the first key(K_(oAMF)′) based on the key (K_(oAMF)) between the terminal device andthe source AMF entity and the random number of the source AMF entity,and derives the communication key between the terminal device and thetarget AMF entity based on the first key (K_(oAMF)′) and the randomnumber of the terminal device. It may be understood that, in this case,the random number of the terminal device may be further used by theterminal device to detect replay, to prevent a replay attack.

Manner 3: In an implementation process of S205, the target AMF entityderives the communication key between the target AMF entity and theterminal device based on the first key (K_(oAMF)′) and a random numberof the target AMF entity. Further, in S206, the NAS SMC sent by thetarget AMF entity to the terminal device further carries the randomnumber of the target AMF entity.

Case 1: The first key (K_(oAMF)′) is derived by the source AMF entitybased on the key (K_(oAMF)) between the terminal device and the sourceAMF entity.

Correspondingly, in S207, the terminal device derives the first key(K_(oAMF)′) based on the key (K_(oAMF)) between the terminal device andthe source AMF entity, and derives the communication key between theterminal device and the target AMF entity based on the first key(K_(oAMF)′) and the random number of the target AMF entity.

Case 2: The first key (K_(oAMF)′) is derived by the source AMF entitybased on the key (K_(oAMF)) between the terminal device and the sourceAMF entity and the random number of the terminal device.

Correspondingly, in S207, the terminal device derives the first key(K_(oAMF)′) based on the key (K_(oAMF)) between the terminal device andthe source AMF entity and the random number of the terminal device, andderives the communication key between the terminal device and the targetAMF entity based on the first key (K_(oAMF)′) and the random number ofthe target AMF entity. It may be understood that, in this case, therandom number of the terminal device may be further used by the terminaldevice to detect replay, to prevent a replay attack.

Further, in S206, the NAS SMC sent by the target AMF entity to theterminal device may further carry the random number of the terminaldevice.

Case 3: The first key (K_(oAMF)′) is derived by the source AMF entitybased on the key (K_(oAMF)) between the terminal device and the sourceAMF entity and the random number of the source AMF entity.

Correspondingly, in S207, the terminal device derives the first key(K_(oAMF)′) based on the key (K_(oAMF)) between the terminal device andthe source AMF entity and the random number of the source AMF entity,and derives the communication key between the terminal device and thetarget AMF entity based on the first key (K_(oAMF)) and the randomnumber of the target AMF entity.

It should be noted that, in case 3, in S206, the NAS SMC sent by thetarget AMF entity to the terminal device may further carry the randomnumber of the terminal device. In this case, the random number of theterminal device is used only by the terminal device to detect replay, toprevent a replay attack.

Manner 4: In an implementation process of S205, the target AMF entityderives a key (which may be referred to as a sixth key and marked asK_(DH)) using a key exchange algorithm based on a random number of thetarget AMF entity and the random number of the terminal device, andderives the communication key between the target AMF entity and theterminal device based on the first key (K_(oAMF)′) and the sixth key(K_(DH)).

Further, in S206, the NAS SMC sent by the target AMF entity to theterminal device further carries the random number of the target AMFentity and the random number of the terminal device.

Case 1: The first key (K_(oAMF)′) is derived by the source AMF entitybased on the key (K_(oAMF)) between the terminal device and the sourceAMF entity.

Correspondingly, in S207, the terminal device derives the first key(K_(oAMF)′) based on the key (K_(oAMF)) between the terminal device andthe source AMF entity, derives the sixth key (K_(DH)) using the keyexchange algorithm based on the random number of the target AMF entityand the random number of the terminal device, and derives thecommunication key between the terminal device and the target AMF entitybased on the first key (K_(oAMF)′) and the sixth key (K_(DH)).Similarly, in this case, the random number of the terminal device may befurther used by the terminal device to detect replay, to prevent areplay attack.

Case 2: The first key (K_(oAMF)′) is derived by the source AMF entitybased on the key (K_(oAMF)) between the terminal device and the sourceAMF entity and the random number of the terminal device.

Correspondingly, in S207, the terminal device derives the first key(K_(oAMF)′) based on the key (K_(oAMF)) between the terminal device andthe source AMF entity and the random number of the terminal device,derives the sixth key (K_(DH)) using the key exchange algorithm based onthe random number of the target AMF entity and the random number of theterminal device, and derives the communication key between the terminaldevice and the target AMF entity based on the first key (K_(oAMF)′) andthe sixth key (K_(DH)). Similarly, in this case, the random number ofthe terminal device may be further used by the terminal device to detectreplay, to prevent a replay attack.

Case 3: The first key (K_(oAMF)′) is derived by the source AMF entitybased on the key (K_(oAMF)) between the terminal device and the sourceAMF entity and the random number of the source AMF entity.

Correspondingly, in S207, the terminal device derives the first key(K_(oAMF)′) based on the key (K_(oAMF)) between the terminal device andthe source AMF entity and the random number of the source AMF entity,derives the sixth key (K_(DH)) using the key exchange algorithm based onthe random number of the target AMF entity and the random number of theterminal device, and derives the communication key between the terminaldevice and the target AMF entity based on the first key (K_(oAMF)′) andthe sixth key (K_(DH)). Similarly, in this case, the random number ofthe terminal device may be further used by the terminal device to detectreplay, to prevent a replay attack.

Manner 5: In an implementation process of S205, the target AMF entityderives a fifth key (referred to as K_(nAMF)′ below) based on the firstkey (K_(oAMF)′) and the random number of the target AMF entity, derivesa sixth key (K_(DH)) using a key exchange algorithm based on a randomnumber of the target AMF entity and the random number of the terminaldevice, and derives the communication key between the target AMF entityand the terminal device based on the fifth key (K_(nAMF)′) and the sixthkey (K_(DH)).

Further, in S206, the NAS SMC sent by the target AMF entity to theterminal device further carries the random number of the target AMFentity and the random number of the terminal device.

Case 1: The first key (K_(oAMF)′) is derived by the source AMF entitybased on the key (K_(oAMF)) between the terminal device and the sourceAMF entity.

Correspondingly, in S207, the terminal device derives the first key(K_(oAMF)′) based on the key (K_(oAMF)) between the terminal device andthe source AMF entity, derives the fifth key (K_(nAMF)′) based on thefirst key (K_(oAMF)′) and the random number of the target AMF entity,derives the sixth key (K_(DH)) using the key exchange algorithm based onthe random number of the target AMF entity and the random number of theterminal device, and derives the communication key between the terminaldevice and the target AMF entity based on the fifth key (K_(nAMF)′) andthe sixth key (K_(DH)). Similarly, in this case, the random number ofthe terminal device may be further used by the terminal device to detectreplay, to prevent a replay attack.

Case 2: The first key (K_(oAMF)′) is derived by the source AMF entitybased on the key (K_(oAMF)) between the terminal device and the sourceAMF entity and the random number of the terminal device.

Correspondingly, in S207, the terminal device derives the first key(K_(oAMF)′) based on the key (K_(oAMF)) between the terminal device andthe source AMF entity and the random number of the terminal device,derives the fifth key (K_(nAMF)′) based on the first key (K_(oAMF)′) andthe random number of the target AMF entity, derives the sixth key(K_(DH)) using the key exchange algorithm based on the random number ofthe target AMF entity and the random number of the terminal device, andderives the communication key between the terminal device and the targetAMF entity based on the fifth key (K_(nAMF)′) and the sixth key(K_(DH)). Similarly, in this case, the random number of the terminaldevice may be further used by the terminal device to detect replay, toprevent a replay attack.

Case 3: The first key (K_(oAMF)′) is derived by the source AMF entitybased on the key (K_(oAMF)) between the terminal device and the sourceAMF entity and the random number of the source AMF entity.

Correspondingly, in S207, the terminal device derives the first key(K_(oAMF)′) based on the key (K_(oAMF)) between the terminal device andthe source AMF entity and the random number of the source AMF entity,derives the fifth key (K_(nAMF)′) based on the first key (K_(oAMF)′) andthe random number of the target AMF entity, derives the sixth key(K_(DH)) using the key exchange algorithm based on the random number ofthe target AMF entity and the random number of the terminal device, andderives the communication key between the terminal device and the targetAMF entity based on the fifth key (K_(nAMF)′) and the sixth key(K_(DH)). Similarly, in this case, the random number of the terminaldevice may be further used by the terminal device to detect replay, toprevent a replay attack.

For example, the key exchange algorithm may be a Diffie-Hellman (DH) keyexchange algorithm, which may be referred to as a DH key exchangealgorithm for short. An implementation principle of the DH key exchangealgorithm is consistent with that in a related technology, and detailsare not described herein.

Optionally, in a second implementation scenario of the foregoingembodiment, S210 to S212 may be implemented in the following manners.

Manner 1: In an implementation process of S210, the target AMF entityuses the third key (K_(AUF)′) as the communication key between thetarget AMF entity and the terminal device.

Case 1: The third key (K_(AUF)′) is derived by the authenticationfunction entity based on the key (K_(AUF)) between the terminal deviceand the authentication function entity.

Correspondingly, in S212, the terminal device derives the third key(K_(AUF)′) based on the key (K_(AUF)) between the terminal device andthe authentication function entity, and uses the third key (K_(AUF)′) asthe communication key between the terminal device and the target AMFentity.

Case 2: The third key (K_(AUF)′) is derived by the authenticationfunction entity based on the key (K_(AUF)) between the terminal deviceand the authentication function entity and the random number of theterminal device.

Correspondingly, in S212, the terminal device derives the third key(K_(AUF)′) based on the key (K_(AUF)) between the terminal device andthe authentication function entity and the random number of the terminaldevice, and uses the third key (K_(AUF)′) as the communication keybetween the terminal device and the target AMF entity.

In this case, in S211, the NAS SMC sent by the target AMF entity to theterminal device may further carry the random number of the terminaldevice.

It may be understood that, in this case, the random number of theterminal device may be further used by the terminal device to detectreplay, to prevent a replay attack.

Case 3: The third key (K_(AUF)′) is derived by the authenticationfunction entity based on the key (K_(AUF)) between the terminal deviceand the authentication function entity and the random number of theauthentication function entity.

Correspondingly, in S212, the terminal device derives the third key(K_(AUF)′) based on the key (K_(AUF)) between the terminal device andthe authentication function entity and the random number of theauthentication function entity, and uses the third key (K_(AUF)′) as thecommunication key between the terminal device and the target AMF entity.

In this case, in S211, the NAS SMC sent by the target AMF entity to theterminal device may further carry the random number of theauthentication function entity.

It should be noted that, in case 3, in S211, the NAS SMC sent by thetarget AMF entity to the terminal device may further carry the randomnumber of the terminal device. In this case, the random number of theterminal device is used only by the terminal device to detect replay, toprevent a replay attack.

Manner 2: In an implementation process of S210, the target AMF entityderives the communication key between the target AMF entity and theterminal device based on the third key (K_(AUF)′) and the random numberof the terminal device. Further, in S211, the NAS SMC sent by the targetAMF entity to the terminal device further carries the random number ofthe terminal device.

Case 1: The third key (K_(AUF)′) is derived by the authenticationfunction entity based on the key (K_(AUF)) between the terminal deviceand the authentication function entity.

Correspondingly, in S212, the terminal device derives the third key(K_(AUF)′) based on the key (K_(AUF)) between the terminal device andthe authentication function entity, and derives the communication keybetween the terminal device and the target AMF entity based on the thirdkey (K_(AUF)′) and the random number of the terminal device.

Case 2: The third key (K_(AUF)′) is derived by the authenticationfunction entity based on the key (K_(AUF)) between the terminal deviceand the authentication function entity and the random number of theterminal device.

Correspondingly, in S212, the terminal device derives the third key(K_(AUF)′) based on the key (K_(AUF)) between the terminal device andthe authentication function entity and the random number of the terminaldevice, and derives the communication key between the terminal deviceand the target AMF entity based on the third key (K_(AUF)′) and randomnumber of the terminal device. It may be understood that, in this case,the random number of the terminal device may be further used by theterminal device to detect replay, to prevent a replay attack.

Case 3: The third key (K_(AUF)′) is derived by the authenticationfunction entity based on the key (K_(AUF)) between the terminal deviceand the authentication function entity and the random number of theauthentication function entity.

Correspondingly, in S212, the terminal device derives the third key(K_(AUF)′) based on the key (K_(AUF)) between the terminal device andthe authentication function entity and the random number of theauthentication function entity, and derives the communication keybetween the terminal device and the target AMF entity based on the thirdkey (K_(AUF)′) and the random number of the terminal device. In thiscase, the random number of the terminal device may be further used bythe terminal device to detect replay, to prevent a replay attack.

Manner 3: In an implementation process of S210, the target AMF entityderives the communication key between the target AMF entity and theterminal device based on the third key (K_(AUF)′) and a random number ofthe target AMF entity. Further, in S211, the NAS SMC sent by the targetAMF entity to the terminal device further carries the random number ofthe target AMF entity.

Case 1: The third key (K_(AUF)′) is derived by the authenticationfunction entity based on the key (K_(AUF)) between the terminal deviceand the authentication function entity.

Correspondingly, in S212, the terminal device derives the third key(K_(AUF)′) based on the key (K_(AUF)) between the terminal device andthe authentication function entity, and derives the communication keybetween the terminal device and the target AMF entity based on the thirdkey (K_(AUF)′) and the random number of the target AMF entity.

Case 2: The third key (K_(AUF)′) is derived by the authenticationfunction entity based on the key (K_(AUF)) between the terminal deviceand the authentication function entity and the random number of theterminal device.

Correspondingly, in S212, the terminal device derives the third key(K_(AUF)′) based on the key (K_(AUF)) between the terminal device andthe authentication function entity and the random number of the terminaldevice, and derives the communication key between the terminal deviceand the target AMF entity based on the third key (K_(AUF)′) and therandom number of the target AMF entity. It may be understood that, inthis case, the random number of the terminal device may be further usedby the terminal device to detect replay, to prevent a replay attack.

Further, in S211, the NAS SMC sent by the target AMF entity to theterminal device may further carry the random number of the terminaldevice.

Case 3: The third key (K_(AUF)′) is derived by the authenticationfunction entity based on the key (K_(AUF)) between the terminal deviceand the authentication function entity and the random number of theauthentication function entity.

Correspondingly, in S212, the terminal device derives the third key(K_(AUF)′) based on the key (K_(AUF)) between the terminal device andthe authentication function entity and the random number of theauthentication function entity, and derives the communication keybetween the terminal device and the target AMF entity based on the thirdkey (K_(AUF)′) and the random number of the target AMF entity.

It should be noted that, in case 3, in S211, the NAS SMC sent by thetarget AMF entity to the terminal device may further carry the randomnumber of the terminal device. In this case, the random number of theterminal device is used only by the terminal device to detect replay, toprevent a replay attack.

Manner 4: In an implementation process of S210, the target AMF entityderives a sixth key (K_(DH)) using a key exchange algorithm based on arandom number of the target AMF entity and the random number of theterminal device, and derives the communication key between the targetAMF entity and the terminal device based on the third key (K_(AUF)′) andthe sixth key (K_(DH)).

Further, in S211, the NAS SMC sent by the target AMF entity to theterminal device further carries the random number of the target AMFentity and the random number of the terminal device.

Case 1: The third key (K_(AUF)′) is derived by the authenticationfunction entity based on the key (K_(AUF)) between the terminal deviceand the authentication function entity.

Correspondingly, in S212, the terminal device derives the third key(K_(AUF)′) based on the key (K_(AUF)) between the terminal device andthe authentication function entity, derives the sixth key (K_(DH)) usingthe key exchange algorithm based on the random number of the target AMFentity and the random number of the terminal device, and derives thecommunication key between the terminal device and the target AMF entitybased on the third key (K_(AUF)′) and the sixth key (K_(DH)). Similarly,in this case, the random number of the terminal device may be furtherused by the terminal device to detect replay, to prevent a replayattack.

Case 2: The third key (K_(AUF)′) is derived by the authenticationfunction entity based on the key (K_(AUF)) between the terminal deviceand the authentication function entity and the random number of theterminal device.

Correspondingly, in S212, the terminal device derives the third key(K_(AUF)′) based on the key (K_(AUF)) between the terminal device andthe authentication function entity and the random number of the terminaldevice, derives the sixth key (K_(DH)) using the key exchange algorithmbased on the random number of the target AMF entity and the randomnumber of the terminal device, and derives the communication key betweenthe terminal device and the target AMF entity based on the third key(K_(AUF)′) and the sixth key (K_(DH)). Similarly, in this case, therandom number of the terminal device may be further used by the terminaldevice to detect replay, to prevent a replay attack.

Case 3: The third key (K_(AUF)′) is derived by the authenticationfunction entity based on the key (K_(AUF)) between the terminal deviceand the authentication function entity and the random number of theauthentication function entity.

Correspondingly, in S212, the terminal device derives the third key(K_(AUF)′) based on the key (K_(AUF)) between the terminal device andthe authentication function entity and the random number of theauthentication function entity, derives the sixth key (K_(DH)) using thekey exchange algorithm based on the random number of the target AMFentity and the random number of the terminal device, and derives thecommunication key between the terminal device and the target AMF entitybased on the third key (K_(AUF)′) and the sixth key (K_(DH)). Similarly,in this case, the random number of the terminal device may be furtherused by the terminal device to detect replay, to prevent a replayattack.

Manner 5: In an implementation process of S210, the target AMF entityderives a key (which may be referred to as a seventh key and marked asK_(nAUF)′) based on the third key (K_(AUF)′) and a random number of thetarget AMF entity, derives a sixth key (K_(DH)) using a key exchangealgorithm based on the random number of the target AMF entity and therandom number of the terminal device, and derives the communication keybetween the target AMF entity and the terminal device based on theseventh key (K_(nAUF)′) and the sixth key (K_(DH)).

Further, in S211, the NAS SMC sent by the target AMF entity to theterminal device further carries the random number of the target AMFentity and the random number of the terminal device.

Case 1: The third key (K_(AUF)′) is derived by the authenticationfunction entity based on the key (K_(AUF)) between the terminal deviceand the authentication function entity.

Correspondingly, in S212, the terminal device derives the third key(K_(AUF)′) based on the key (K_(AUF)) between the terminal device andthe authentication function entity, derives the seventh key (K_(nAUF)′)based on the third key (K_(AUF)′) and the random number of the targetAMF entity, derives the sixth key (K_(DH)) using the key exchangealgorithm based on the random number of the target AMF entity and therandom number of the terminal device, and derives the communication keybetween the terminal device and the target AMF entity based on theseventh key (K_(nAUF)′) and the sixth key (K_(DH)). Similarly, in thiscase, the random number of the terminal device may be further used bythe terminal device to detect replay, to prevent a replay attack.

Case 2: The third key (K_(AUF)′) is derived by the authenticationfunction entity based on the key (K_(AUF)) between the terminal deviceand the authentication function entity and the random number of theterminal device.

Correspondingly, in S212, the terminal device derives the third key(K_(AUF)′) based on the key (K_(AUF)) between the terminal device andthe authentication function entity and the random number of the terminaldevice, derives the seventh key (K_(nAUF)′) based on the third key(K_(AUF)′) and the random number of the target AMF entity, derives thesixth key (K_(DH)) using the key exchange algorithm based on the randomnumber of the target AMF entity and the random number of the terminaldevice, and derives the communication key between the terminal deviceand the target AMF entity based on the seventh key (K_(nAUF)′) and thesixth key (K_(DH)). Similarly, in this case, the random number of theterminal device may be further used by the terminal device to detectreplay, to prevent a replay attack.

Case 3: The third key (K_(AUF)′) is derived by the authenticationfunction entity based on the key (K_(AUF)) between the terminal deviceand the authentication function entity and the random number of theauthentication function entity.

Correspondingly, in S212, the terminal device derives the third key(K_(AUF)′) based on the key (K_(AUF)) between the terminal device andthe authentication function entity and the random number of the sourceAMF entity, derives the seventh key (K_(nAUF)′) based on the third key(K_(AUF)′) and the random number of the target AMF entity, derives thesixth key (K_(DH)) using the key exchange algorithm based on the randomnumber of the target AMF entity and the random number of the terminaldevice, and derives the communication key between the terminal deviceand the target AMF entity based on the seventh key (K_(nAUF)′) and thesixth key (K_(DH)). Similarly, in this case, the random number of theterminal device may be further used by the terminal device to detectreplay, to prevent a replay attack.

It should be noted that this embodiment imposes no limitation on the KDFused in the foregoing implementations.

FIG. 3 is a schematic flowchart of a key obtaining method according toan embodiment of this application. In the key obtaining method providedin this embodiment, a target AMF entity determines a communication keybetween the target AMF entity and a terminal device based on securityrelated information and an intermediate key sent by a source AMF entity,and instructs the terminal device to derive a corresponding key. In thisway, key isolation is achieved between the target AMF entity and thesource AMF entity. For a same or similar step and related detail, referto descriptions of the foregoing embodiment in FIG. 2A and FIG. 2B.Details are not described again in this embodiment.

As shown in FIG. 3, the key obtaining method provided in this embodimentincludes the following steps.

S301. A target AMF entity receives a first message.

The first message may be used to request to register a terminal device,and may be, for example, a registration request message. In FIG. 3, anexample in which a (R)AN sends the first message to the target AMFentity is used for description.

S302. The target AMF entity sends a second message to a source AMFentity based on the first message.

The second message may be used to request a security context of theterminal device from the source AMF entity, the second message may be aninformation request message, and the second message includes anidentifier of the terminal device.

S303. The source AMF entity derives a first key based on a key betweenthe source AMF entity and a terminal device.

Optionally, the source AMF entity may derive the first key (K_(oAMF)′)using a KDF based on the key (K_(oAMF)) between the source AMF entityand the terminal device. For details, refer to related descriptions ofthe embodiment shown in FIG. 2A and FIG. 2B.

For example, the source AMF entity may derive the first key (K_(oAMF)′)using a KDF based on the key (K_(oAMF)) between the source AMF entityand the terminal device and a random number of the terminal device.

For another example, the source AMF entity may derive the first key(K_(oAMF)′) using a KDF based on the key (K_(oAMF)) between the sourceAMF entity and the terminal device and a random number of the source AMFentity.

S304. The target AMF entity receives a third message from the source AMFentity.

The third message may be used to respond to the second message. Forexample, the security context of the terminal device is sent to thetarget AMF entity using the third message. The third message may be aninformation response message. The third message carries the first key(K_(oAMF)′). For the first key, refer to related descriptions of theembodiment shown in FIG. 2A and FIG. 2B.

S305. The target AMF entity determines a communication key between thetarget AMF entity and the terminal device based on security relatedinformation and the first key.

In a possible case, when the security related information is apreconfigured policy and the policy is used to indicate to use a keyreceived from the source AMF entity, or when the security relatedinformation is key isolation information of the target AMF entity andthe key isolation information is used to indicate that a key of thetarget AMF entity is not totally isolated from a key of the source AMFentity, or when the security related information is a security status ofthe source AMF entity and the security status is used to indicate thatthe source AMF entity is secure, the target AMF entity determines thecommunication key between the target AMF entity and the terminal devicebased on the first key (K_(oAMF)′).

In another possible case, when the target AMF entity determines, basedon the security related information, to use a key received from thesource AMF entity, the target AMF entity determines the communicationkey between the target AMF entity and the terminal device based on thefirst key.

For an implementation in which the target AMF entity determines, basedon the security related information, to use the key received from thesource AMF entity, refer to related descriptions of S204 in theembodiment shown in FIG. 2A and FIG. 2B.

For an implementation in which the target AMF entity determines thecommunication key between the target AMF entity and the terminal devicebased on the first key (K_(oAMF)′), refer to related descriptions ofstep S205. Details are not described again.

S306. The target AMF entity sends a NAS SMC to the terminal device.

As described in the foregoing embodiment shown in FIG. 2A and FIG. 2B,the NAS SMC carries indication information, and the indicationinformation is used to indicate the terminal device to derive thecommunication key between the terminal device and the target AMF entitybased on the key (K_(oAMF)) between the source AMF entity and theterminal device.

S307. The terminal device determines the communication key between theterminal device and the target AMF entity according toindicateindication information.

For step S307, refer to a related implementation of S207. Details arenot described again.

Optionally, the method further includes the following steps S308 andS309:

S308. The terminal device sends a NAS SMP to the target AMF entity.

S309. The target AMF entity sends a sixth message to the terminaldevice.

The sixth message is used to notify the terminal device thatregistration of the terminal device is accepted, and the sixth messagemay be a registration accept message.

In the key obtaining method provided in this embodiment, the target AMFentity determines the communication key between the target AMF entityand the terminal device based on the security related information usingthe intermediate key sent by the source AMF entity.

The intermediate key is obtained by the source AMF entity throughderivation based on the key between the source AMF entity and theterminal device, and therefore the target AMF entity cannot learn of acommunication key used between the source AMF entity and the terminaldevice. In this way, key isolation is achieved between the target AMFentity and the source AMF entity, thereby effectively avoiding asecurity risk and improving communication security.

FIG. 4A and FIG. 4B are schematic flowcharts of a key obtaining methodaccording to an embodiment of this application. In the key obtainingmethod provided in this embodiment, a target AMF entity requests a newkey from an authentication function entity to determine a communicationkey between the target AMF entity and a terminal device, and instructsthe terminal device to derive a corresponding key. In this way, keyisolation is achieved between the target AMF entity and a source AMFentity. For a same or similar step and related detail, refer todescriptions of the foregoing embodiment in FIG. 2A and FIG. 2B. Detailsare not described again in this embodiment.

As shown in FIG. 4A and FIG. 4B, the key obtaining method provided inthis embodiment includes the following steps.

S401. A target AMF entity receives a first message.

The first message may be used to request to register a terminal device,and the first message may be a registration request message. In theaccompanying drawings corresponding to this embodiment, an example inwhich a (R)AN sends the first message to the target AMF entity is usedfor description.

S402. The target AMF entity sends a second message to a source AMFentity based on the first message.

The second message may be used to request a security context of theterminal device from the source AMF entity, the second message may be aninformation request message, and the second message may include anidentifier of the terminal device.

S403. The source AMF entity derives a first key based on a key betweenthe source AMF entity and a terminal device.

For the key between the source AMF entity and the terminal device, referto related descriptions of step 203. Details are not described again.

S404. The target AMF entity receives a third message from the source AMFentity.

The third message may carry the first key. The third message may be usedto respond to the second message. For example, the security context ofthe terminal device is sent to the target AMF entity using the thirdmessage. The third message may be an information response message, andthe third message carries the first key.

S405. The target AMF entity sends a fourth message to an authenticationfunction entity based on the third message.

The fourth message is used to request a key, the fourth message may be akey request message, and the fourth message includes the identifier ofthe terminal device.

The third message may carry an address of the authentication functionentity, and the target AMF entity may send the fourth message to theauthentication function entity based on the address. Obviously, thethird message may be only used to trigger the target AMF entity to sendthe fourth message, and this is not limited.

Sending the fourth message to the authentication function entity in S405may be implemented in the following manner:

Manner 1: The target AMF entity sends the fourth message to theauthentication function entity based on security related information.

For the security related information, refer to related descriptions ofthe embodiment shown in FIG. 2A and FIG. 2B. Details are not describedagain.

In an example, when the security related information is a preconfiguredpolicy and the policy is used to indicate to use a key received from theauthentication function entity, the target AMF entity sends the fourthmessage to the authentication function entity.

In another example, when the security related information is keyisolation information of the target AMF entity and the key isolationinformation is used to indicate that a key of the target AMF entity istotally isolated from a key of the source AMF entity, the target AMFentity sends the fourth message to the authentication function entity.

In still another example, when the security related information is asecurity status of the source AMF entity and the security status is usedto indicate that the source AMF entity is not secure, the target AMFentity sends the fourth message to the authentication function entity.

Manner 2: When the target AMF entity determines, based on securityrelated information, not to use a key received from the source AMFentity, the target AMF entity sends the fourth message to theauthentication function entity.

For an implementation in which the target AMF entity determines, basedon the security related information, not to use the key received fromthe source AMF entity, refer to related descriptions of S204 in theembodiment shown in FIG. 2A and FIG. 2B.

It should be noted that sending the fourth message to the authenticationfunction entity in S405 may be replaced with manner 1 or manner 2.

Obviously, content included in the security related information may beused together. For details, refer to related descriptions of S204.

S406. The authentication function entity derives a third key based on akey shared between the authentication function entity and the terminaldevice.

For the key shared between the authentication function entity and theterminal device, refer to related descriptions of S208. Details are notdescribed again.

Optionally, the authentication function entity may derive the third key(K_(AUF)′) using a KDF based on the key (K_(AUF)) shared between theauthentication function entity and the terminal device. For details,refer to related descriptions of the embodiment shown in FIG. 2A andFIG. 2B.

Optionally, the authentication function entity may derive the third key(K_(AUF)′) using a KDF based on the key (K_(AUF)) shared between theauthentication function entity and the terminal device and a randomnumber of the terminal device. Further, the fourth message furtherincludes the random number of the terminal device.

Optionally, the authentication function entity may derive the third key(K_(AUF)′) using a KDF based on the key (K_(AUF)) shared between theauthentication function entity and the terminal device and a randomnumber of the authentication function entity.

S407. The target AMF entity receives a fifth message from theauthentication function entity.

The fifth message is used to respond to the fourth message, the fifthmessage may be a key response message, and the fifth message carries thethird key (K_(AUF)′).

S408. The target AMF entity determines a communication key between thetarget AMF entity and the terminal device based on the third key.

S409. The target AMF entity sends a NAS SMC to the terminal device.

As described in the foregoing embodiment shown in FIG. 2A and FIG. 2B,the NAS SMC carries indication information, and the indicationinformation is used to indicate the terminal device to derive thecommunication key between the terminal device and the target AMF entitybased on the key (K_(AUF)) shared between the authentication functionentity and the terminal device.

S410. The terminal device determines the communication key between theterminal device and the target AMF entity according toindicateindication information.

Optionally, the method further includes the following steps S411 andS412:

S411. The terminal device sends a NAS SMP to the target AMF entity.

S412. The target AMF entity sends a sixth message to the terminaldevice.

The sixth message may be used to notify the terminal device thatregistration of the terminal device is accepted, and may be, forexample, a registration accept message.

In the key obtaining method provided in this embodiment, the target AMFentity directly requests a new key from the authentication functionentity to determine the communication key between the target AMF entityand the terminal device. In this way, key isolation is achieved betweenthe target AMF entity and the source AMF entity, thereby effectivelyavoiding a security risk and improving communication security.

FIG. 5 is a schematic flowchart of a key obtaining method according toan embodiment of this application. The key obtaining method provided inthis embodiment is performed by a terminal device, namely, a method usedby the terminal device to obtain a key. In the key obtaining methodprovided in this embodiment, the terminal device derives a correspondingkey according to a NAS SMC sent by a target AMF entity, such that acommunication key between the terminal device and the target AMF entityis isolated from a communication key between the terminal device and asource AMF entity. For a same or similar step and related detail, referto descriptions of the foregoing embodiment in FIG. 2A and FIG. 2B.Details are not described again in this embodiment.

As shown in FIG. 5, the key obtaining method provided in this embodimentincludes the following steps.

S501. A terminal device receives a NAS SMC sent by a target AMF entity.

The NAS SMC may carry indication information, and the indicationinformation is used to indicate the terminal device to derive acommunication key between the terminal device and the target AMF entitybased on a key between the terminal device and a source AMF entity, orthe indication information is used to indicate the terminal device toderive a communication key between the terminal device and the targetAMF entity based on a key shared between the terminal device and anauthentication function entity.

For the communication key, the indication information, and the like,refer to related descriptions of the embodiment shown in FIG. 2A andFIG. 2B. Details are not described again.

S502. The terminal device determines a communication key between theterminal device and the target AMF entity according to the NAS SMC.

When the indication information is used to indicate the terminal deviceto derive the communication key between the terminal device and thetarget AMF entity based on the key between the terminal device and thesource AMF entity, for an implementation process in which the terminaldevice determines the communication key between the terminal device andthe target AMF entity, refer to the descriptions of S207 in theforegoing embodiment in FIG. 2A and FIG. 2B. Details are not describedherein again.

When the indication information is used to indicate the terminal deviceto derive the communication key between the terminal device and thetarget AMF entity based on the key shared between the terminal deviceand the authentication function entity, for an implementation process inwhich the terminal device determines the communication key between theterminal device and the target AMF entity, refer to the descriptions ofS212 in the foregoing embodiment in FIG. 2A and FIG. 2B. Details are notdescribed herein again.

Optionally, before S501, the method further includes the following step.

S503. The terminal device sends a first message to the target AMFentity.

The first message may be used to request to register the terminaldevice, and the first message may be a registration request message.

In an example of this application, the terminal device may further sendthe first message to a (R)AN, and the (R)AN selects a target AMF entityfor the terminal device based on the first message, for example, mayselect the target AMF entity based on an identifier of the terminaldevice carried in the first message, or may select the target AMF entitybased on a radio access type (RAT) or network slice selection assistanceinformation (NSSAI) in the first message, and sends the first message tothe target AMF entity.

Further, after S503, the method may further include the following steps.

S504. The target AMF entity sends a second message to a source AMFentity based on the first message.

The second message may be used to request a security context of theterminal device from the source AMF entity, the second message may be aninformation request message, and the second message includes theidentifier of the terminal device.

S505. The source AMF entity derives a first key based on a key betweenthe source AMF entity and the terminal device.

S506. The source AMF entity sends a third message to the target AMFentity.

The third message may be used to respond to the second message, thethird message may be used to send the security context of the terminaldevice to the target AMF entity, and the third message may be aninformation response message. As described in the foregoing embodimentshown in FIG. 2A and FIG. 2B, the third message carries the first key(K_(oAMF)′).

S507. The target AMF entity determines, based on security relatedinformation, whether to use the first key.

For example, if the target AMF entity determines, based on the securityrelated information, to use the first key, the indication informationcarried in the NAS SMC that is sent by the target AMF entity and that isreceived by the terminal device in S501 is used to indicate the terminaldevice to derive the communication key between the terminal device andthe target AMF entity based on the key between the terminal device andthe source AMF entity.

For example, if the target AMF entity determines, based on the securityrelated information, not to use the first key, the indicationinformation carried in the NAS SMC that is sent by the target AMF entityand that is received by the terminal device in S501 is used to indicatethe terminal device to derive the communication key between the terminaldevice and the target AMF entity based on the key shared between theterminal device and the authentication function entity.

Optionally, the method may further include the following steps.

S508. The terminal device sends a NAS SMP to the target AMF entity.

S509. The terminal device receives a sixth message from the target AMFentity.

The sixth message is used to notify the terminal device thatregistration of the terminal device is accepted, and the sixth messagemay be a registration accept message.

In the key obtaining method provided in this embodiment, the terminaldevice derives a corresponding key according to the NAS SMC sent by thetarget AMF entity, such that the communication key between the terminaldevice and the target AMF entity is isolated from the communication keybetween the terminal device and the source AMF entity. This caneffectively avoid a security risk and improve communication security.

Based on the idea that is the same as that of the foregoing methodembodiments, the embodiments of this application further provide aplurality of key obtaining apparatuses. The plurality of apparatuses maybe implemented using software, hardware, or a combination of softwareand hardware, and may be configured to implement the key obtainingmethod provided in the foregoing method embodiments. The apparatus partcorresponds to the foregoing method, and corresponding content and atechnical effect of the apparatus part are the same as those of theforegoing method and are not described herein again.

FIG. 6 is a schematic structural diagram of a key obtaining apparatusaccording to an embodiment of this application. As shown in FIG. 6, theapparatus may be implemented as a part or all of a target AMF entityusing software, hardware, or a combination of software and hardware. Theapparatus may include a receiving module 61, a sending module 62, and adetermining module 63.

The receiving module 61 is configured to receive a first message, wherethe first message is used to request to register a terminal device.

The sending module 62 is configured to send a second message to a sourceAMF entity based on the first message, where the second message includesan identifier of the terminal device.

The receiving module 61 is further configured to receive a third messagefrom the source AMF entity, where the third message is used to respondto the second message, the third message carries a first key(K_(oAMF)′), and the first key is obtained by the source AMF entitythrough derivation based on a key (K_(oAMF)) between the source AMFentity and the terminal device.

The determining module 63 is configured to determine a communication keybetween a target AMF entity and the terminal device based on securityrelated information and the first key (K_(oAMF)′).

For example, the key between the source AMF entity and the terminaldevice includes a communication key between the source AMF entity andthe terminal device or a key shared between the source AMF entity andthe terminal device, and the key shared between the source AMF entityand the terminal device is an MSK, or a key generated based on an MSK,or a key generated based on a CK and an IK.

For example, the security related information may include: apreconfigured policy, where the policy is used to indicate to use a keyreceived from the source AMF entity, or the policy is used to indicateto use a key received from an authentication function entity; or keyisolation information of the target AMF entity, where the key isolationinformation is used to indicate whether a key of the target AMF entityis totally isolated from a key of the source AMF entity; or a securitystatus of the source AMF entity, where the security status is used toindicate whether the source AMF entity is secure.

Optionally, in actual application, the determining module 63 may beconfigured such that when the security related information is thepreconfigured policy and the policy is used to indicate to use the keyreceived from the source AMF entity, the determining module 63determines the communication key between the target AMF entity and theterminal device based on the first key (K_(oAMF)′). Alternatively, thedetermining module 63 may be configured such that when the securityrelated information is the key isolation information of the target AMFentity and the key isolation information is used to indicate that thekey of the target AMF entity is not totally isolated from the key of thesource AMF entity, the determining module 63 determines thecommunication key between the target AMF entity and the terminal devicebased on the first key (K_(oAMF)′). Alternatively, the determiningmodule 63 may be configured such that when the security relatedinformation is the security status of the source AMF entity and thesecurity status is used to indicate that the source AMF entity issecure, the determining module 63 determines the communication keybetween the target AMF entity and the terminal device based on the firstkey (K_(oAMF)′). Alternatively, the determining module 63 may beconfigured such that when the target AMF entity determines, based on thesecurity related information, to use the key received from the sourceAMF entity, the determining module 63 determines the communication keybetween the target AMF entity and the terminal device based on the firstkey (K_(oAMF)′).

Optionally, in actual application, the determining module 63 may befurther configured such that when the security related information isthe preconfigured policy and the policy is used to indicate to use thekey received from the source AMF entity, the determining module 63determines to use the key received from the source AMF entity.Alternatively, the determining module 63 may be further configured suchthat when the security related information is the key isolationinformation of the target AMF entity and the key isolation informationis used to indicate that the key of the target AMF entity is not totallyisolated from the key of the source AMF entity, the determining module63 determines to use the key received from the source AMF entity.Alternatively, the determining module 63 may be further configured suchthat when the security related information is the security status of thesource AMF entity and the security status is used to indicate that thesource AMF entity is secure, the determining module 63 determines to usethe key received from the source AMF entity.

Optionally, in actual application, the determining module 63 may use thefirst key (K_(oAMF)′) as the communication key between the target AMFentity and the terminal device.

Optionally, in actual application, the determining module 63 may derivethe communication key between the target AMF entity and the terminaldevice based on the first key (K_(oAMF)′) and a random number of theterminal device.

Optionally, in actual application, the determining module 63 may derivethe communication key between the target AMF entity and the terminaldevice based on the first key (K_(oAMF)′) and a random number of thetarget AMF entity.

Optionally, in actual application, the determining module 63 may derivea sixth key (K_(DH)) using a key exchange algorithm based on a randomnumber of the target AMF entity and a random number of the terminaldevice, and derive the communication key between the target AMF entityand the terminal device based on the first key (K_(oAMF)′) and the sixthkey (K_(DH)).

Optionally, in actual application, the determining module 63 may derivea sixth key (K_(DH)) using a key exchange algorithm based on a randomnumber of the target AMF entity and a random number of the terminaldevice, derive a fifth key (K_(nAMF)′) based on the first key and therandom number of the target AMF entity, and derive the communication keybetween the target AMF entity and the terminal device based on the sixthkey (K_(DH)) and the fifth key (K_(nAMF)′).

In actual application, the first key (K_(oAMF)′) may be obtained by thesource AMF entity through derivation based on the communication keybetween the source AMF entity and the terminal device and a randomnumber of the source AMF entity.

In actual application, the first message may include the random numberof the terminal device.

Optionally, in actual application, the sending module 62 may be furtherconfigured to send a NAS SMC to the terminal device, where the NAS SMCcarries indication information, and the indication information is usedto indicate the terminal device to derive the communication key betweenthe terminal device and the target AMF entity using the key (K_(oAMF))between the source AMF entity and the terminal device.

The key obtaining apparatus provided in this embodiment can performfunctions performed by the target AMF entity in the method embodimentshown in FIG. 2A and FIG. 2B or FIG. 3. An implementation principle anda technical effect of this embodiment are similar to those of the methodembodiment and are not described herein again.

FIG. 7 is a schematic structural diagram of a key obtaining apparatusaccording to an embodiment of this application. As shown in FIG. 7, theapparatus may be implemented as a part or all of a target AMF entityusing software, hardware, or a combination of software and hardware. Theapparatus may include a receiving module 71, a sending module 72, and adetermining module 73.

The receiving module 71 is configured to receive a first message, wherethe first message is used to request to register a terminal device.

The sending module 72 is configured to send a second message to a sourceAMF entity based on the first message, where the second message includesan identifier of the terminal device. The receiving module 71 is furtherconfigured to receive a third message from the source AMF entity, wherethe third message is used to respond to the second message.

The sending module 72 is further configured to send a fourth message toan authentication function entity based on the third message, where thefourth message is used to request a key, and the fourth message includesthe identifier of the terminal device.

The receiving module 71 is further configured to receive a fifth messagefrom the authentication function entity, where the fifth message carriesa third key (K_(AUF)′), and the third key (K_(AUF)′) is obtained by theauthentication function entity through derivation based on a key(K_(AUF)) shared between the authentication function entity and theterminal device.

The determining module 73 is configured to determine a communication keybetween a target AMF entity and the terminal device based on the thirdkey (K_(AUF)′).

For example, the key shared between the authentication function entityand the terminal device is an EMSK, or a key generated based on an EMSK,or a key generated based on a CK and an IK.

For example, the sending module 72 may be configured to send the fourthmessage to the authentication function entity based on security relatedinformation. Alternatively, when the determining module 73 determines,based on the security related information, not to use a key receivedfrom the source AMF entity, the sending module 72 may be configured tosend the fourth message to the authentication function entity.

In actual application, the security related information may include: apreconfigured policy, where the policy is used to indicate to use thekey received from the source AMF entity, or the policy is used toindicate to use a key received from the authentication function entity;or key isolation information of the target AMF entity, where the keyisolation information is used to indicate whether a key of the targetAMF entity is totally isolated from a key of the source AMF entity; or asecurity status of the source AMF entity, where the security status isused to indicate whether the source AMF entity is secure.

Optionally, in actual application, the sending module 72 may beconfigured such that when the security related information is thepreconfigured policy and the policy is used to indicate to use the keyreceived from the authentication function entity, the sending module 72sends the fourth message to the authentication function entity.Alternatively, the sending module 72 may be configured such that whenthe security related information is the key isolation information of thetarget AMF entity and the key isolation information is used to indicatethat the key of the target AMF entity is totally isolated from the keyof the source AMF entity, the sending module 72 sends the fourth messageto the authentication function entity. Alternatively, the sending module72 may be configured such that when the security related information isthe security status of the source AMF entity and the security status isused to indicate that the source AMF entity is not secure, the sendingmodule 72 sends the fourth message to the authentication functionentity.

Optionally, in actual application, the determining module 73 may befurther configured such that when the security related information isthe preconfigured policy and the policy is used to indicate to use thekey received from the source AMF entity, the determining module 73determines not to use the key received from the source AMF entity.Alternatively, the determining module 73 may be further configured suchthat when the security related information is the key isolationinformation of the target AMF entity and the key isolation informationis used to indicate that the key of the target AMF entity is not totallyisolated from the key of the source AMF entity, the determining module73 determines not to use the key received from the source AMF entity.Alternatively, the determining module 73 may be further configured suchthat when the security related information is the security status of thesource AMF entity and the security status is used to indicate that thesource AMF entity is secure, the determining module 73 determines not touse the key received from the source AMF entity.

Optionally, in actual application, the determining module 73 may use thethird key (K_(AUF)′) as the communication key between the target AMFentity and the terminal device.

Optionally, in actual application, the determining module 73 may derivethe communication key between the target AMF entity and the terminaldevice based on the third key (K_(AUF)′) and a random number of theterminal device.

Optionally, in actual application, the determining module 73 may derivethe communication key between the target AMF entity and the terminaldevice based on the third key (K_(AUF)′) and a random number of thetarget AMF entity.

Optionally, in actual application, the determining module 73 may derivea sixth key (K_(DH)) using a key exchange algorithm based on a randomnumber of the target AMF entity and a random number of the terminaldevice, and derive the communication key between the target AMF entityand the terminal device based on the third key (K_(AUF)′) and the sixthkey (K_(DH)).

Optionally, in actual application, the determining module 73 may derivea sixth key (K_(DH)) using a key exchange algorithm based on a randomnumber of the target AMF entity and a random number of the terminaldevice, derive a seventh key (K_(nAUF)′) based on the third key(K_(AUF)′) and the random number of the target AMF entity, and derivethe communication key between the target AMF entity and the terminaldevice based on the sixth key (K_(DH)) and the seventh key (K_(nAUF)′).

Optionally, the third key (K_(AUF)′) is obtained by the authenticationfunction entity through derivation based on the key shared between theauthentication function entity and the terminal device and the randomnumber of the terminal device.

Optionally, the third key (K_(AUF)′) is obtained by the authenticationfunction entity through derivation based on the key shared between theauthentication function entity and the terminal device and a randomnumber of the authentication function entity.

Optionally, the first message includes the random number of the terminaldevice.

Optionally, in actual application, the sending module 72 may be furtherconfigured to send a NAS SMC to the terminal device, where the NAS SMCcarries indication information, and the indication information is usedto indicate the terminal device to derive the communication key betweenthe terminal device and the target AMF entity based on the key sharedbetween the authentication function entity and the terminal device.

The key obtaining apparatus provided in this embodiment can performfunctions performed by the target AMF in the method embodiment shown inFIG. 2A and FIG. 2B or FIG. 4A and FIG. 4B. An implementation principleand a technical effect of this embodiment are similar to those of themethod embodiment and are not described herein again.

FIG. 8 is a schematic structural diagram of a key obtaining apparatusaccording to an embodiment of this application. As shown in FIG. 8, theapparatus may be implemented as a part or all of a terminal device usingsoftware, hardware, or a combination of software and hardware. Theapparatus may include a receiving module 81 and a determining module 83.

The receiving module 81 is configured to receive a NAS SMC sent by atarget AMF entity, where the NAS SMC carries indication information, andthe indication information is used to indicate a terminal device toderive a communication key between the terminal device and the targetAMF entity based on a key (K_(oAMF)) between the terminal device and asource AMF entity, or the indication information is used to indicate theterminal device to derive a communication key between the terminaldevice and the target AMF entity based on a key (K_(AUF)) shared betweenthe terminal device and an authentication function entity.

The determining module 83 is configured to determine the communicationkey between the terminal device and the target AMF entity according tothe indication information.

For example, the key between the source AMF entity and the terminaldevice includes a communication key between the source AMF entity andthe terminal device or a key shared between the source AMF entity andthe terminal device, and the key shared between the source AMF entityand the terminal device is a master session key MSK, or a key generatedbased on an MSK, or a key generated based on a cipher key CK and anintegrity key IK.

For example, the key (K_(AUF)) shared between the authenticationfunction entity and the terminal device is an EMSK, or a key generatedbased on an EMSK, or a key generated based on a CK and an IK.

In a first possible design, the determining module 83 is configured suchthat when the indication information is used to indicate the terminaldevice to derive the communication key between the terminal device andthe target AMF entity based on the key (K_(oAMF)) between the terminaldevice and the source AMF entity, the determining module 83 derives afirst key (K_(oAMF)′) based on the key (K_(oAMF)) between the terminaldevice and the source AMF entity, and uses the first key (K_(oAMF)′) asthe communication key between the terminal device and the target AMFentity. Alternatively, the determining module 83 is configured such thatwhen the indication information is used to indicate the terminal deviceto derive the communication key between the terminal device and thetarget AMF entity based on the key (K_(AUF)) shared between the terminaldevice and the authentication function entity, the determining module 83derives a third key (K_(AUF)′) based on the key shared between theterminal device and the authentication function entity, and uses thethird key (K_(AUF)′) as the communication key between the terminaldevice and the target AMF entity.

In a second possible design, the determining module 83 is configuredsuch that when the indication information is used to indicate theterminal device to derive the communication key between the terminaldevice and the target AMF entity based on the key between the terminaldevice and the source AMF entity, the determining module 83 derives afirst key (K_(oAMF)′) based on the key between the terminal device andthe source AMF entity, and derives the communication key between theterminal device and the target AMF entity based on the first key(K_(oAMF)′) and a random number of the terminal device. Alternatively,the determining module 83 is configured such that when the indicationinformation is used to indicate the terminal device to derive thecommunication key between the terminal device and the target AMF entitybased on the key shared between the terminal device and theauthentication function entity, the determining module 83 derives athird key (K_(AUF)′) based on the key shared between the terminal deviceand the authentication function entity, and derives the communicationkey between the terminal device and the target AMF entity based on thethird key (K_(AUF)′) and a random number of the terminal device.

In a third possible design, the determining module 83 is configured suchthat when the indication information is used to indicate the terminaldevice to derive the communication key between the terminal device andthe target AMF entity based on the key between the terminal device andthe source AMF entity, the determining module 83 derives a first key(K_(oAMF)′) based on the key between the terminal device and the sourceAMF entity, and derives the communication key between the terminaldevice and the target AMF entity based on the first key (K_(oAMF)′) anda random number of the target AMF entity; Alternatively, the determiningmodule 83 is configured such that when the indication information isused to indicate the terminal device to derive the communication keybetween the terminal device and the target AMF entity based on the keyshared between the terminal device and the authentication functionentity, the determining module 83 derives a third key (K_(AUF)′) basedon the key shared between the terminal device and the authenticationfunction entity, and derives the communication key between the terminaldevice and the target AMF entity based on the third key (K_(AUF)′) and arandom number of the target AMF entity.

In a fourth possible design, the determining module 83 is configuredsuch that when the indication information is used to indicate theterminal device to derive the communication key between the terminaldevice and the target AMF entity based on the key between the terminaldevice and the source AMF entity, the determining module 83 derives afirst key (K_(oAMF)′) based on the key between the terminal device andthe source AMF entity, derives a sixth key (K_(DH)) using a key exchangealgorithm based on a random number of the target AMF entity and a randomnumber of the terminal device, and derives the communication key betweenthe terminal device and the target AMF entity based on the first key(K_(oAMF)′) and the sixth key (K_(DH)). Alternatively, the determiningmodule 83 is configured such that when the indication information isused to indicate the terminal device to derive the communication keybetween the terminal device and the target AMF entity based on the keyshared between the terminal device and the authentication functionentity, the determining module 83 derives a third key (K_(AUF)′) basedon the key shared between the terminal device and the authenticationfunction entity, derives a sixth key (K_(DH)) using a key exchangealgorithm based on a random number of the target AMF entity and a randomnumber of the terminal device, and derives the communication key betweenthe terminal device and the target AMF entity based on the third key(K_(AUF)′) and the sixth key (K_(DH)).

In a fifth possible design, the determining module 83 is configured suchthat when the indication information is used to indicate the terminaldevice to derive the communication key between the terminal device andthe target AMF entity based on the key between the terminal device andthe source AMF entity, the determining module 83 derives a first key(K_(oAMF)′) based on the key between the terminal device and the sourceAMF entity, derives a fifth key (K_(nAMF)′) based on the first key(K_(oAMF)′) and a random number of the target AMF entity, derives asixth key (K_(DH)) using a key exchange algorithm based on the randomnumber of the target AMF entity and a random number of the terminaldevice, and derives the communication key between the terminal deviceand the target AMF entity based on the fifth key (K_(nAMF)′) and thesixth key (K_(DH)). Alternatively, the determining module 83 isconfigured such that when the indication information is used to indicatethe terminal device to derive the communication key between the terminaldevice and the target AMF entity based on the key shared between theterminal device and the authentication function entity, the determiningmodule 83 derives a third key (K_(AUF)′) based on the key shared betweenthe terminal device and the authentication function entity, derives aseventh key (K_(nAUF)′) based on the third key (K_(AUF)′) and a randomnumber of the target AMF entity, derives a sixth key (K_(DH)) using akey exchange algorithm based on the random number of the target AMFentity and a random number of the terminal device, and derives thecommunication key between the terminal device and the target AMF entitybased on the sixth key (K_(DH)) and the seventh key (K_(nAUF)′).

Optionally, in actual application, the determining module 83 may befurther configured to: derive the first key (K_(oAMF)′) based on the keybetween the terminal device and the source AMF entity and the randomnumber of the terminal device, or derive the first key (K_(oAMF)′) basedon the key between the terminal device and the source AMF entity and arandom number of the source AMF entity.

Optionally, in actual application, the determining module 83 may befurther configured to: derive the third key (K_(AUF)′) based on the keyshared between the terminal device and the authentication functionentity and the random number of the terminal device, or derive the thirdkey (K_(AUF)′) based on the key shared between the terminal device andthe authentication function entity and a random number of theauthentication function entity.

Optionally, the apparatus may further include a sending module 82. Inactual application, the sending module 82 may be configured to send afirst message to a (R)AN, where the first message is used to request toregister the terminal device; or send a first message to the target AMFentity, where the first message is used to request to register theterminal device.

Further, the first message may carry the random number of the terminaldevice.

The key obtaining apparatus provided in this embodiment can performfunctions performed by the terminal device in the foregoing methodembodiment. An implementation principle and a technical effect of thisembodiment are similar to those of the method embodiment and are notdescribed herein again.

FIG. 9 is a schematic structural diagram of a key obtaining apparatusaccording to an embodiment of this application. As shown in FIG. 9, theapparatus may be implemented as a part or all of a source AMF entityusing software, hardware, or a combination of software and hardware. Theapparatus may include a receiving module 91, a sending module 92, and akey derivation module 93.

The receiving module 91 is configured to receive a second message from atarget AMF entity, where the second message is used to request asecurity context of a terminal device, the second message may be aninformation request message, and the second message includes anidentifier of the terminal device.

The key derivation module 93 is configured to derive a first key(K_(oAMF)′) based on a key (K_(oAMF)) between a source AMF entity andthe terminal device.

The sending module 92 is configured to send a third message to thetarget AMF entity, where the third message is used to respond to thesecond message, the third message is used to send the security contextof the terminal device to the target AMF entity, the third message maybe an information response message, and the third message carries thefirst key (K_(oAMF)′).

For example, the key between the source AMF entity and the terminaldevice includes a communication key between the source AMF entity andthe terminal device or a key shared between the source AMF entity andthe terminal device, and the key shared between the source AMF entityand the terminal device is an MSK, or a key generated based on an MSK,or a key generated based on a CK and an IK.

Optionally, in actual application, the key derivation module 93 may beconfigured to derive the first key (K_(oAMF)′) using a KDF based on thekey (K_(oAMF)) between the source AMF entity and the terminal device.

Optionally, in actual application, the key derivation module 93 may beconfigured to derive the first key (K_(oAMF)′) using a KDF based on thekey (K_(oAMF)) between the source AMF entity and the terminal device anda random number of the terminal device.

Optionally, the second message may carry the random number of theterminal device.

Optionally, in actual application, the key derivation module 93 may beconfigured to derive the first key (K_(oAMF)′) using a KDF based on thekey (K_(oAMF)) between the source AMF entity and the terminal device anda random number of the source AMF entity.

The key obtaining apparatus provided in this embodiment can performfunctions performed by the source AMF entity in the foregoing methodembodiment. An implementation principle and a technical effect of thisembodiment are similar to those of the method embodiment and are notdescribed herein again.

FIG. 10 is a schematic structural diagram of a key obtaining apparatusaccording to an embodiment of this application. As shown in FIG. 10, theapparatus may be implemented as a part or all of an authenticationfunction entity using software, hardware, or a combination of softwareand hardware. The apparatus may include a receiving module 101, asending module 102, and a key derivation module 103.

The receiving module 101 is configured to receive a fourth message sentby an AMF entity, where the fourth message is used to request a key, thefourth message may be a key request message, and the fourth messageincludes an identifier of a terminal device.

The key derivation module 103 is configured to derive a third key(K_(AUF)′) based on a key (K_(AUF)) shared between an authenticationfunction entity and the terminal device.

The sending module 102 is configured to send a fifth message to thetarget AMF entity, where the fifth message is used to respond to thefourth message, the fifth message may be a key response message, and thefifth message carries the third key (K_(AUF)′).

For example, the key (K_(AUF)) shared between the authenticationfunction entity and the terminal device is an EMSK, or a key generatedbased on an EMSK, or a key generated based on a CK and an IK.

Optionally, in actual application, the key derivation module 103 may beconfigured to derive the third key (K_(AUF)′) using a KDF based on thekey (K_(AUF)) shared between the authentication function entity and theterminal device.

Optionally, in actual application, the key derivation module 103 may beconfigured to derive the third key (K_(AUF)′) using a KDF based on thekey (K_(AUF)) shared between the authentication function entity and theterminal device and a random number of the terminal device.

Optionally, the fourth message may carry the random number of theterminal device.

Optionally, in actual application, the key derivation module 103 may beconfigured to derive the third key (K_(AUF)′) using a KDF based on thekey (K_(AUF)) shared between the authentication function entity and theterminal device and a random number of the authentication functionentity.

The key obtaining apparatus provided in this embodiment can performfunctions performed by the authentication function entity in theforegoing method embodiment. An implementation principle and a technicaleffect of this embodiment are similar to those of the method embodimentand are not described herein again.

Based on the idea that is the same as that of the foregoing methodembodiments, the embodiments of this application further provide aplurality of network devices and a terminal device. The plurality ofnetwork devices and the terminal device may be configured to implementthe key obtaining method provided in the foregoing method embodiments.The device part corresponds to the foregoing method, and correspondingcontent and a technical effect of the device part are the same as thoseof the foregoing method and are not described herein again.

FIG. 11 is a schematic structural diagram of an AMF entity according toan embodiment of this application. As shown in FIG. 11, the AMF entityincludes a transceiver 111, a memory 112, a processor 113, and at leastone communications bus 114.

The memory 112 stores a software program, the memory 112 may include ahigh-speed RAM memory, and may further include a non-volatile memoryNVM, for example, at least one magnetic disk memory, and the memory 112may store various programs, to complete various processing functions andimplement method steps in this embodiment. The processor 113 is coupledto the memory 112, and the communications bus 114 is configured toimplement communication connection between elements. Optionally, thetransceiver 111 in this embodiment may be a radio frequency module, abaseband module, or a communication interface module.

In this embodiment, the transceiver 111 is configured to: receive afirst message, where the first message is used to request to register aterminal device; send a second message to a source AMF entity based onthe first message, where the second message includes an identifier ofthe terminal device; and receive a third message from the source AMFentity, where the third message is used to respond to the secondmessage, the third message carries a first key (K_(oAMF)*), and thefirst key (K_(oAMF)′) is obtained by the source AMF entity throughderivation based on a key (K_(oAMF)) between the source AMF entity andthe terminal device.

For example, the key between the source AMF entity and the terminaldevice includes a communication key between the source AMF entity andthe terminal device or a key shared between the source AMF entity andthe terminal device, and the key shared between the source AMF entityand the terminal device is an MSK, or a key generated based on an MSK,or a key generated based on a CK and an IK.

In this embodiment, the processor 113 is configured to determine acommunication key between the AMF entity and the terminal device basedon security related information and the first key (K_(oAMF)′).

For example, the security related information may include: apreconfigured policy, where the policy is used to indicate to use a keyreceived from the source AMF entity, or the policy is used to indicateto use a key received from an authentication function entity; or keyisolation information of the AMF entity, where the key isolationinformation is used to indicate whether a key of the AMF entity istotally isolated from a key of the source AMF entity; or a securitystatus of the source AMF entity, where the security status is used toindicate whether the source AMF entity is secure.

Optionally, in actual application, the processor 113 may be configuredsuch that when the security related information is the preconfiguredpolicy and the policy is used to indicate to use the key received fromthe source AMF entity, or when the security related information is thekey isolation information of the AMF entity and the key isolationinformation is used to indicate that the key of the AMF entity is nottotally isolated from the key of the source AMF entity, or when thesecurity related information is the security status of the source AMFentity and the security status is used to indicate that the source AMFentity is secure, the processor 113 determines the communication keybetween the AMF entity and the terminal device based on the first key(K_(oAMF)′); or when the AMF entity determines, based on the securityrelated information, to use the key received from the source AMF entity,the processor 113 determines the communication key between the AMFentity and the terminal device based on the first key (K_(oAMF)′).

Optionally, in actual application, the processor 113 may be furtherconfigured such that when the security related information is thepreconfigured policy and the policy is used to indicate to use the keyreceived from the source AMF entity, the processor 113 determines to usethe key received from the source AMF entity; or when the securityrelated information is the key isolation information of the AMF entityand the key isolation information is used to indicate that the key ofthe AMF entity is not totally isolated from the key of the source AMFentity, the processor 113 determines to use the key received from thesource AMF entity; or when the security related information is thesecurity status of the source AMF entity and the security status is usedto indicate that the source AMF entity is secure, the processor 113determines to use the key received from the source AMF entity.

Optionally, in actual application, the processor 113 may use the firstkey (K_(oAMF)′) as the communication key between the AMF entity and theterminal device.

Optionally, in actual application, the processor 113 may derive thecommunication key between the AMF entity and the terminal device basedon the first key (K_(oAMF)′) and a random number of the terminal device.

Optionally, in actual application, the processor 113 may derive thecommunication key between the AMF entity and the terminal device basedon the first key (K_(oAMF)′) and a random number of the AMF entity.

Optionally, in actual application, the processor 113 may derive a sixthkey (K_(DH)) using a key exchange algorithm based on a random number ofthe AMF entity and a random number of the terminal device, and derivethe communication key between the AMF entity and the terminal devicebased on the first key (K_(oAMF)′) and the sixth key (K_(OH)).

Optionally, in actual application, the processor 113 may derive a sixthkey (K_(DH)) using a key exchange algorithm based on a random number ofthe AMF entity and a random number of the terminal device, derive afifth key (K_(nAMF)′) based on the first key and the random number ofthe AMF entity, and derive the communication key between the AMF entityand the terminal device based on the sixth key (K_(DH)) and the fifthkey (K_(nAMF)′).

In actual application, the first key (K_(oAMF)′) may be obtained by thesource AMF entity through derivation based on the communication keybetween the source AMF entity and the terminal device and a randomnumber of the source AMF entity.

In actual application, the first key (K_(oAMF)′) may be obtained by thesource AMF entity through derivation based on the communication keybetween the source AMF entity and the terminal device and a randomnumber of the source AMF entity.

In actual application, the first message may include the random numberof the terminal device.

Optionally, in actual application, the transceiver 111 may be furtherconfigured to send a NAS SMC to the terminal device, where the NAS SMCcarries indication information, and the indication information is usedto indicate the terminal device to derive the communication key betweenthe terminal device and the AMF entity using the key (K_(oAMF)) betweenthe source AMF entity and the terminal device.

The AMF entity provided in this embodiment can perform functionsperformed by the target AMF in the foregoing method embodiment. Animplementation principle and a technical effect of this embodiment aresimilar to those of the method embodiment and are not described hereinagain.

FIG. 12 is a schematic structural diagram of an AMF entity according toan embodiment of this application. As shown in FIG. 12, the AMF entityincludes a transceiver 121, a memory 122, a processor 123, and at leastone communications bus 124.

The memory 122 stores a software program, the memory 122 may include ahigh-speed RAM memory, and may further include a non-volatile memoryNVM, for example, at least one magnetic disk memory, and the memory 122may store various programs, to complete various processing functions andimplement method steps in this embodiment. The processor 123 is coupledto the memory 122, and the communications bus 124 is configured toimplement communication connection between elements. Optionally, thetransceiver 121 in this embodiment may be a radio frequency module, abaseband module, or a communication interface module on a networkdevice.

In this embodiment, the transceiver 121 is configured to: receive afirst message, where the first message is used to request to register aterminal device; send a second message to a source AMF entity based onthe first message, where the second message includes an identifier ofthe terminal device; receive a third message from the source AMF entity,where the third message is used to respond to the second message; send afourth message to an authentication function entity based on the thirdmessage, where the fourth message is used to request a key, and thefourth message includes the identifier of the terminal device; andreceive a fifth message from the authentication function entity, wherethe fifth message carries a third key (K_(AUF)′), and the third key(K_(AUF)′) is obtained by the authentication function entity throughderivation based on a key (K_(AUF)) shared between the authenticationfunction entity and the terminal device.

In this embodiment, the processor 123 is configured to determine acommunication key between the AMF entity and the terminal device basedon the third key (K_(AUF)′).

For example, the key shared between the authentication function entityand the terminal device is an EMS K, or a key generated based on an EMSK, or a key generated based on a CK and an IK.

For example, the transceiver 121 may be configured to: send the fourthmessage to the authentication function entity based on security relatedinformation; or when the processor 123 determines, based on the securityrelated information, not to use a key received from the source AMFentity, send the fourth message to the authentication function entity.

For example, the security related information may include: apreconfigured policy, where the policy is used to indicate to use thekey received from the source AMF entity, or the policy is used toindicate to use a key received from the authentication function entity;or key isolation information of the AMF entity, where the key isolationinformation is used to indicate whether a key of the AMF entity istotally isolated from a key of the source AMF entity; or a securitystatus of the source AMF entity, where the security status is used toindicate whether the source AMF entity is secure.

Optionally, in actual application, the transceiver 121 may be configuredsuch that when the security related information is the preconfiguredpolicy and the policy is used to indicate to use the key received fromthe authentication function entity, the transceiver 121 sends the fourthmessage to the authentication function entity; or when the securityrelated information is the key isolation information of the AMF entityand the key isolation information is used to indicate that the key ofthe AMF entity is totally isolated from the key of the source AMFentity, the transceiver 121 sends the fourth message to theauthentication function entity; or when the security related informationis the security status of the source AMF entity and the security statusis used to indicate that the source AMF entity is not secure, thetransceiver 121 sends the fourth message to the authentication functionentity.

Optionally, in actual application, the processor 123 may be furtherconfigured such that when the security related information is thepreconfigured policy and the policy is used to indicate to use the keyreceived from the source AMF entity, the processor 123 determines not touse the key received from the source AMF entity; or when the securityrelated information is the key isolation information of the AMF entityand the key isolation information is used to indicate that the key ofthe AMF entity is not totally isolated from the key of the source AMFentity, the processor 123 determines not to use the key received fromthe source AMF entity; or when the security related information is thesecurity status of the source AMF entity and the security status is usedto indicate that the source AMF entity is secure, the processor 123determines not to use the key received from the source AMF entity.

Optionally, in actual application, the processor 123 may use the thirdkey (K_(AUF)′) as the communication key between the AMF entity and theterminal device.

Optionally, in actual application, the processor 123 may derive thecommunication key between the AMF entity and the terminal device basedon the third key (K_(AUF)′) and a random number of the terminal device.

Optionally, in actual application, the processor 123 may derive thecommunication key between the AMF entity and the terminal device basedon the third key (K_(AUF)′) and a random number of the AMF entity.

Optionally, in actual application, the processor 123 may derive a sixthkey (K_(DH)) using a key exchange algorithm based on a random number ofthe AMF entity and a random number of the terminal device, and derivethe communication key between the AMF entity and the terminal devicebased on the third key (K_(AUF)′) and the sixth key (K_(DH)).

Optionally, in actual application, the processor 123 may derive a sixthkey (K_(DH)) using a key exchange algorithm based on a random number ofthe AMF entity and a random number of the terminal device, derive aseventh key (K_(nAUF)′) based on the third key (K_(AUF)′) and the randomnumber of the AMF entity, and derive the communication key between theAMF entity and the terminal device based on the sixth key (K_(DH)) andthe seventh key (K_(nAUF)′).

Optionally, the third key (K_(AUF)′) is obtained by the authenticationfunction entity through derivation based on the key shared between theauthentication function entity and the terminal device and the randomnumber of the terminal device.

Optionally, the third key (K_(AUF)′) is obtained by the authenticationfunction entity through derivation based on the key shared between theauthentication function entity and the terminal device and a randomnumber of the authentication function entity.

Optionally, the first message includes the random number of the terminaldevice.

Optionally, in actual application, the transceiver 121 may be furtherconfigured to send a NAS SMC to the terminal device, where the NAS SMCcarries indication information, and the indication information is usedto indicate the terminal device to derive the communication key betweenthe terminal device and the AMF entity based on the key shared betweenthe authentication function entity and the terminal device.

The AMF entity provided in this embodiment can perform functionsperformed by the target AMF entity in the foregoing method embodiment.An implementation principle and a technical effect of this embodimentare similar to those of the method embodiment and are not describedherein again.

FIG. 13 is a schematic structural diagram of a terminal device accordingto an embodiment of this application. As shown in FIG. 13, the terminaldevice includes a transceiver 131, a memory 132, a processor 133, and atleast one communications bus 134.

The memory 132 stores a software program, the memory 132 may include ahigh-speed RAM memory, and may further include a non-volatile memoryNVM, for example, at least one magnetic disk memory, and the memory 132may store various programs, to complete various processing functions andimplement method steps in this embodiment. The processor 133 is coupledto the memory 132, and the communications bus 134 is configured toimplement communication connection between elements. Optionally, thetransceiver 131 in this embodiment may be a radio frequency module or abaseband module on the terminal device.

In this embodiment, the transceiver 131 is configured to receive a NASSMC sent by a target AMF entity, where the NAS SMC carries indicationinformation, and the indication information is used to indicate aterminal device to derive a communication key between the terminaldevice and the target AMF entity based on a key (K_(oAMF)) between theterminal device and a source AMF entity, or the indication informationis used to indicate the terminal device to derive a communication keybetween the terminal device and the target AMF entity based on a key(K_(AUF)) shared between the terminal device and an authenticationfunction entity.

In this embodiment, the processor 133 is configured to determine thecommunication key between the terminal device and the target AMF entityaccording to the indication information.

For example, the key between the source AMF entity and the terminaldevice includes a communication key between the source AMF entity andthe terminal device or a key shared between the source AMF entity andthe terminal device, and the key shared between the source AMF entityand the terminal device is an MSK, or a key generated based on an MSK,or a key generated based on a CK and an IK.

For example, the key (K_(AUF)) shared between the authenticationfunction entity and the terminal device is an EMSK, or a key generatedbased on an EMSK, or a key generated based on a CK and an IK.

In a first possible design, the processor 133 is configured such thatwhen the indication information is used to indicate the terminal deviceto derive the communication key between the terminal device and thetarget AMF entity based on the key (K_(oAMF)) between the terminaldevice and the source AMF entity, the processor 133 derives a first key(K_(oAMF)′) based on the key (K_(oAMF)) between the terminal device andthe source AMF entity, and uses the first key (K_(oAMF)′) as thecommunication key between the terminal device and the target AMF entity;or when the indication information is used to indicate the terminaldevice to derive the communication key between the terminal device andthe target AMF entity based on the key (K_(AUF)) shared between theterminal device and the authentication function entity, the processor133 derives a third key (K_(AUF)′) based on the key shared between theterminal device and the authentication function entity, and uses thethird key (K_(AUF)′) as the communication key between the terminaldevice and the target AMF entity.

In a second possible design, the processor 133 is configured such thatwhen the indication information is used to indicate the terminal deviceto derive the communication key between the terminal device and thetarget AMF entity based on the key between the terminal device and thesource AMF entity, the processor 133 derives a first key (K_(oAMF)′)based on the key between the terminal device and the source AMF entity,and derives the communication key between the terminal device and thetarget AMF entity based on the first key (K_(oAMF)′) and a random numberof the terminal device; or when the indication information is used toindicate the terminal device to derive the communication key between theterminal device and the target AMF entity based on the key sharedbetween the terminal device and the authentication function entity, theprocessor 133 derives a third key (K_(AUF)′) based on the key sharedbetween the terminal device and the authentication function entity, andderives the communication key between the terminal device and the targetAMF entity based on the third key (K_(AUF)′) and a random number of theterminal device.

In a third possible design, the processor 133 is configured such thatwhen the indication information is used to indicate the terminal deviceto derive the communication key between the terminal device and thetarget AMF entity based on the key between the terminal device and thesource AMF entity, the processor 133 derives a first key (K_(oAMF)′)based on the key between the terminal device and the source AMF entity,and derives the communication key between the terminal device and thetarget AMF entity based on the first key (K_(oAMF)′) and a random numberof the target AMF entity; or when the indication information is used toindicate the terminal device to derive the communication key between theterminal device and the target AMF entity based on the key sharedbetween the terminal device and the authentication function entity, theprocessor 133 derives a third key (K_(AUF)′) based on the key sharedbetween the terminal device and the authentication function entity, andderives the communication key between the terminal device and the targetAMF entity based on the third key (K_(AUF)′) and a random number of thetarget AMF entity.

In a fourth possible design, the processor 133 is configured such thatwhen the indication information is used to indicate the terminal deviceto derive the communication key between the terminal device and thetarget AMF entity based on the key between the terminal device and thesource AMF entity, the processor 133 derives a first key (K_(oAMF)′)based on the key between the terminal device and the source AMF entity,derives a sixth key (K_(DH)) using a key exchange algorithm based on arandom number of the target AMF entity and a random number of theterminal device, and derives the communication key between the terminaldevice and the target AMF entity based on the first key (K_(oAMF)′) andthe sixth key (K_(DH)); or when the indication information is used toindicate the terminal device to derive the communication key between theterminal device and the target AMF entity based on the key sharedbetween the terminal device and the authentication function entity, theprocessor 133 derives a third key (K_(AUF)′) based on the key sharedbetween the terminal device and the authentication function entity,derives a sixth key (K_(DH)) using a key exchange algorithm based on arandom number of the target AMF entity and a random number of theterminal device, and derives the communication key between the terminaldevice and the target AMF entity based on the third key (K_(AUF)′) andthe sixth key (K_(DH)).

In a fifth possible design, the processor 133 is configured such thatwhen the indication information is used to indicate the terminal deviceto derive the communication key between the terminal device and thetarget AMF entity based on the key between the terminal device and thesource AMF entity, the processor 133 derives a first key (K_(oAMF)′)based on the key between the terminal device and the source AMF entity,derives a fifth key (K_(nAMF)′) based on the first key (K_(oAMF)′) and arandom number of the target AMF entity, derives a sixth key (K_(DH))using a key exchange algorithm based on the random number of the targetAMF entity and a random number of the terminal device, and derives thecommunication key between the terminal device and the target AMF entitybased on the fifth key (K_(nAMF)′) and the sixth key (K_(DH)); or whenthe indication information is used to indicate the terminal device toderive the communication key between the terminal device and the targetAMF entity based on the key shared between the terminal device and theauthentication function entity, the processor 133 derives a third key(K_(AUF)′) based on the key shared between the terminal device and theauthentication function entity, derives a seventh key (K_(nAUF)′) basedon the third key (K_(AUF)′) and a random number of the target AMFentity, derives a sixth key (K_(DH)) using a key exchange algorithmbased on the random number of the target AMF entity and a random numberof the terminal device, and derives the communication key between theterminal device and the target AMF entity based on the sixth key(K_(DH)) and the seventh key (K_(nAUF)′).

Optionally, in actual application, the processor 133 may be furtherconfigured to: derive the first key (K_(oAMF)) based on the key betweenthe terminal device and the source AMF entity and the random number ofthe terminal device, or derive the first key (K_(oAMF)′) based on thekey between the terminal device and the source AMF entity and a randomnumber of the source AMF entity.

Optionally, in actual application, the processor 133 may be furtherconfigured to: derive the third key (K_(AUF)′) based on the key sharedbetween the terminal device and the authentication function entity andthe random number of the terminal device, or derive the third key(K_(AUF)′) based on the key shared between the terminal device and theauthentication function entity and a random number of the authenticationfunction entity.

Optionally, in actual application, the transceiver 131 may be configuredto send a first message to a (R)AN, where the first message is used torequest to register the terminal device; or send a first message to thetarget AMF entity, where the first message is used to request toregister the terminal device.

Further, the first message may carry the random number of the terminaldevice.

The terminal device provided in this embodiment can perform functionsperformed by the terminal device in the foregoing method embodiment. Animplementation principle and a technical effect of this embodiment aresimilar to those of the method embodiment and are not described hereinagain.

FIG. 14 is a schematic structural diagram of an authentication functionentity according to an embodiment of this application. As shown in FIG.14, the authentication function entity includes a transceiver 141, amemory 142, a processor 143, and at least one communications bus 144.

The memory 142 stores a software program, the memory 142 may include ahigh-speed RAM memory, and may further include a non-volatile memoryNVM, for example, at least one magnetic disk memory, and the memory 142may store various programs, to complete various processing functions andimplement method steps in this embodiment. The processor 143 is coupledto the memory 142, and the communications bus 144 is configured toimplement communication connection between elements. Optionally, thetransceiver 141 in this embodiment may be a radio frequency module, abaseband module, or a communication interface module on a networkdevice.

In this embodiment, the transceiver 141 is configured to receive afourth message sent by an AMF entity, where the fourth message is usedto request a key, the fourth message may be a key request message, andthe fourth message includes an identifier of a terminal device. Theprocessor 143 is configured to derive a third key (K_(AUF)′) based on akey (K_(AUF)) shared between an authentication function entity and theterminal device. The transceiver 141 is further configured to send afifth message to the target AMF entity, where the fifth message is usedto respond to the fourth message, the fifth message may be a keyresponse message, and the fifth message carries the third key(K_(AUF)′).

For example, the key (K_(AUF)) shared between the authenticationfunction entity and the terminal device is an EMSK, or a key generatedbased on an EMSK, or a key generated based on a CK and an IK.

Optionally, in actual application, the processor 143 may be configuredto derive the third key (K_(AUF)′) using a KDF based on the key(K_(AUF)) shared between the authentication function entity and theterminal device.

Optionally, in actual application, the processor 143 may be configuredto derive the third key (K_(AUF)′) using a KDF based on the key(K_(AUF)) shared between the authentication function entity and theterminal device and a random number of the terminal device.

Optionally, the fourth message may carry the random number of theterminal device.

Optionally, in actual application, the processor 143 may be configuredto derive the third key (K_(AUF)′) using a KDF based on the key(K_(AUF)) shared between the authentication function entity and theterminal device and a random number of the authentication functionentity.

The authentication function entity provided in this embodiment canperform functions performed by the authentication function entity in theforegoing method embodiment. An implementation principle and a technicaleffect of this embodiment are similar to those of the method embodimentand are not described herein again.

FIG. 15 is a schematic structural diagram of an AMF entity according toan embodiment of this application. As shown in FIG. 15, the AMF entityincludes a transceiver 151, a memory 152, a processor 153, and at leastone communications bus 154.

The memory 152 stores a software program, the memory 152 may include ahigh-speed RAM memory, and may further include a non-volatile memoryNVM, for example, at least one magnetic disk memory, and the memory 152may store various programs, to complete various processing functions andimplement method steps in this embodiment. The processor 153 is coupledto the memory 152, and the communications bus 154 is configured toimplement communication connection between elements. Optionally, thetransceiver 151 in this embodiment may be a radio frequency module, abaseband module, or a communication interface module on a networkdevice.

In this embodiment, the transceiver 151 is configured to receive asecond message from a target AMF entity, where the second message isused to request a security context of a terminal device, the secondmessage may be an information request message, and the second messageincludes an identifier of the terminal device. The processor 153 isconfigured to derive a first key (K_(oAMF)′) based on a key (K_(oAMF))between the AMF entity and the terminal device. The transceiver 151 isfurther configured to send a third message to the target AMF entity,where the third message is used to respond to the second message, thethird message is used to send the security context of the terminaldevice to the target AMF entity, the third message may be an informationresponse message, and the third message carries the first key(K_(oAMF)′).

For example, the key between the source AMF entity and the terminaldevice includes a communication key between the source AMF entity andthe terminal device or a key shared between the source AMF entity andthe terminal device, and the key shared between the source AMF entityand the terminal device is an MSK, or a key generated based on an MSK,or a key generated based on a CK and an IK.

Optionally, in actual application, the processor 153 may be configuredto derive the first key (K_(oAMF)′) using a KDF based on the key(K_(oAMF)) between the AMF entity and the terminal device.

Optionally, in actual application, the processor 153 may be configuredto derive the first key (K_(oAMF)′) using a KDF based on the key(K_(oAMF)) between the AMF entity and the terminal device and a randomnumber of the terminal device.

Optionally, the second message may carry the random number of theterminal device.

Optionally, in actual application, the processor 153 may be configuredto derive the first key (K_(oAMF)′) using a KDF based on the key(K_(oAMF)) between the AMF entity and the terminal device and a randomnumber of the AMF entity.

The AMF entity provided in this embodiment can perform functionsperformed by the source AMF entity in the foregoing method embodiment.An implementation principle and a technical effect of this embodimentare similar to those of the method embodiment and are not describedherein again.

In addition, an embodiment of this application further provides aplurality of communications systems.

A first communications system includes a target AMF entity having thekey obtaining apparatus provided in the foregoing embodiment shown inFIG. 6 or FIG. 7, a source AMF entity having the key obtaining apparatusprovided in the foregoing embodiment shown in FIG. 9, an authenticationfunction entity having the key obtaining apparatus provided in theforegoing embodiment shown in FIG. 10, and a terminal device having thekey obtaining apparatus provided in the foregoing embodiment shown inFIG. 8.

A second communications system includes the target AMF entity providedin the foregoing embodiment shown in FIG. 11 or FIG. 12, the source AMFentity provided in the foregoing embodiment shown in FIG. 15, theauthentication function entity provided in the foregoing embodimentshown in FIG. 14, and the terminal device provided in the foregoingembodiment shown in FIG. 13.

The methods or algorithm steps described with reference to the contentdisclosed in this application may be implemented by hardware, may beimplemented by a processor by executing a software instruction, or maybe implemented using a computer program product. The softwareinstruction may include a corresponding software module. The softwaremodule may be stored in a RAM memory, a flash memory, a ROM memory, anEPROM memory, an EEPROM memory, a register, a hard disk, a removablehard disk, a CD-ROM memory, or a storage medium in any other formswell-known in the art. A storage medium used as an example is coupled tothe processor, such that the processor can read information from thestorage medium, and can write information into the storage medium.Certainly, the storage medium may be a component of the processor. Theprocessor and the storage medium may be located in an ASIC. In addition,the ASIC may be located in user equipment. Certainly, the processor andthe storage medium may exist in the user equipment as discretecomponents.

Persons skilled in the art should be aware that in one or more of theforegoing examples, the functions described in this application may beimplemented using hardware, software, firmware, or any combinationthereof. When implemented by software, these functions may be stored ina computer-readable medium or transmitted as one or more instructions orcode in the computer-readable medium. The computer-readable mediumincludes a computer storage medium and a communications medium, and thecommunications medium includes any medium that enables a computerprogram to be transmitted from one place to another. The storage mediummay be any available medium accessible to a general-purpose or dedicatedcomputer.

In the embodiments provided in this application, it should be understoodthat the disclosed system, device and method may be implemented in othermanners without departing from the scope of this application. Forexample, the described embodiment is merely an example. For example, themodule or unit division is merely logical function division and may beother division in actual implementation. For example, a plurality ofunits or components may be combined or integrated into another system,or some features may be ignored or not performed. The units described asseparate parts may be or may not be physically separate, and partsdisplayed as units may be or may not be physical units, may be locatedin one position, or may be distributed on a plurality of network units.Some or all of the modules may be selected based on actual needs toachieve the objectives of the solutions of the embodiments. Persons ofordinary skill in the art may understand and implement the embodimentsof this application without creative efforts.

In addition, the schematic diagrams illustrating the system, device,method, and different embodiments may be combined or integrated withother systems, modules, technologies or methods without departing fromthe scope of this application. In addition, the displayed or discussedmutual couplings or direct couplings or communication connection may beimplemented through some interfaces. The indirect couplings orcommunication connection between the apparatuses or units may beimplemented in electronic, mechanic, or other forms.

It can be understood that “a plurality of” in the embodiments of thisapplication refers to two or more than two. Descriptions such as “first”and “second” in the embodiments of this application are merely used forindicating and distinguishing between objects, do not show a sequence,do not represent that a quantity of devices or messages is limited inthe embodiments of this application, for example, there may be one ormore first keys, and do not constitute any limitation on the embodimentsof this application.

Finally, it should be noted that the foregoing embodiments are merelyintended for describing the technical solutions of this applicationother than limiting this application. Although this application isdescribed in detail with reference to the foregoing embodiments, personsof ordinary skill in the art should understand that they may still makemodifications to the technical solutions described in the foregoingembodiments or make equivalent replacements to some or all technicalfeatures thereof, without departing from the scope of the technicalsolutions of the embodiments of this application.

1. A method for security handling in mobility of a terminal device,comprising: receiving, by a target access and mobility managementfunction (AMF) entity, a first message for registering the terminaldevice; sending, by the target AMF entity, a second message to a sourceAMF entity after receiving the first message, wherein the second messageincludes an identifier of the terminal device; deriving, by the sourceAMF entity, a first key based on a key between the source AMF entity andthe terminal device; sending, by the source AMF entity, the first key tothe target AMF entity; determining, by the target AMF entity afterreceiving the first key, to use the first key based on security relatedinformation; and determining, by the target AMF entity after determiningto use the first key, a communication key between the target AMF entityand the terminal device based on the first key.
 2. The method accordingto claim 1, further comprising: sending, by the target AMF entity, tothe terminal device, a non-access stratum security mode command (NASSMC) that carries indication information instructing the terminal deviceto derive the first key.
 3. The method according to claim 2, furthercomprising: receiving, by the terminal device, the NAS SMC; deriving, bythe terminal device, the first key based on the key between the sourceAMF entity and the terminal device; and deriving, by the terminaldevice, the communication key between the terminal device and the targetAMF entity according to the first key.
 4. The method according to claim1, wherein the security related information comprises key isolationinformation of the target AMF entity or a security status of the sourceAMF entity.
 5. The method according to claim 1, wherein the securityrelated information comprises a preconfigured policy that indicates touse the first key received from the source AMF entity.
 6. The methodaccording to claim 1, wherein the second message is for requesting asecurity context of the terminal device.
 7. A method for securityhandling in mobility of a terminal device, comprising: receiving, by atarget access and mobility management function (AMF) entity, a firstmessage for registering the terminal device; sending, by the target AMFentity, a second message to a source AMF entity after receiving thefirst message, wherein the second message includes an identifier of theterminal device; deriving, by the source AMF entity, a first key basedon a key between the source AMF entity and the terminal device; sending,by the source AMF entity, the first key to the target AMF entity;determining, by the target AMF entity after receiving the first key, notto use the first key based on security related information; sending, bythe target AMF entity, a key request message to an authenticationfunction entity after determining not to use the first key; deriving, bythe authentication function entity, a second key based on a shared keybetween the authentication function entity and the terminal device;sending, by the authentication function entity, the second key to thetarget AMF entity; and determining, by the target AMF entity, acommunication key between the target AMF entity and the terminal devicebased on the second key.
 8. The method according to claim 7, furthercomprising sending, by the target AMF entity, to the terminal device, anon-access stratum security mode command (NAS SMC) that carriesindication information instructing the terminal device to derive thecommunication key between the terminal device and the target AMF entity.9. The method according to claim 8, further comprising: receiving, bythe terminal device, the NAS SMC; and deriving, by the terminal device,the communication key based on the shared key between the terminaldevice and the authentication function entity.
 10. The method accordingto claim 7, wherein the security related information comprises keyisolation information of the target AMF entity or a security status ofthe source AMF entity.
 11. The method according to claim 7, wherein thesecurity related information comprises a preconfigured policy thatindicates to use the first key received.
 12. The method according toclaim 7, wherein the second message is for requesting a security contextof the terminal device.
 13. A communication system, comprising: a targetaccess and mobility management function (AMF) entity; and a source AMFentity coupled to the AMF entity, wherein the target AMF entity isconfigured to receive a first message for registering a terminal device,and to send a second message to the source AMF entity after receivingthe first message, wherein the second message includes an identifier ofthe terminal device, wherein the source AMF entity is configured toderive a first key based on a key between the source AMF entity and theterminal device, and to send the first key to the target AMF entity,wherein the target AMF entity is further configured to determine to usethe first key based on security related information after receiving thefirst key, and to derive a communication key based on the first keyafter determining to use the first key.
 14. The communication systemaccording to claim 13, wherein the target AMF entity is configured tosend to the terminal device a non-access stratum security mode command(NAS SMC) that carries indication information instructing the terminaldevice to derive the first key.
 15. The communication system accordingto claim 13, wherein the security related information comprises keyisolation information of the target AMF entity or a security status ofthe source AMF entity.
 16. The communication system according to claim13, wherein the security related information comprises a preconfiguredpolicy that indicates to use the first key received from the source AMFentity.
 17. The communication system according to claim 13, wherein thesecond message is for requesting a security context of the terminaldevice.
 18. A communication system, comprising: a target access andmobility management function (AMF) entity; a source AMF entity coupledto the target AMF entity; and an authentication function entity coupledto the target AMF entity, wherein the target AMF entity is configured toreceive a first message for registering a terminal devices and to send asecond message to the source AMF entity after receiving the firstmessage, wherein the second message includes an identifier of theterminal device, wherein the source AMF entity is configured to derive afirst key based on a key between the source AMF entity and the terminaldevice, and to send the first key to the target AMF entity, wherein thetarget AMF entity is further configured to determine not to use thefirst key based on security related information after receiving thefirst key, and to send a key request message to the authenticationfunction entity after determining not to use the first key, wherein theauthentication function entity is configured to derive a second keybased on a shared key between the authentication function entity and theterminal devices and to send the second key to the target AMF entity,and wherein the target AMF entity is further configured to determine acommunication key between the target AMF entity and the terminal devicebased on the second key.
 19. The communication system according to claim18, wherein the target AMF entity is further configured to send to theterminal device a non-access stratum security mode command (NAS SMC)that carries indication information instructing the terminal device toderive the communication key.
 20. The communication system according toclaim 18, wherein the security related information comprises keyisolation information of the target AMF entity or a security status ofthe source AMF entity.
 21. The communication system according to claim18, wherein the security related information comprises a preconfiguredpolicy that indicates to use the first key received from the source AMFentity.
 22. The communication system according to claim 18, wherein thesecond message is for requesting a security context of the terminaldevice.